问题
I am trying to integrate vaadin with my spring mvc application. I have a some url with jsp files that spring mvc controller use them For example : mysite.com/spring/ mysite.com/spring/examples mysite.com/spring/examples/1.jsp
I want to add vaadin in this path: mysite.com/vaadin/MainUI
here is my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.1"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd"
metadata-complete="true">
<display-name>vaadin-spring</display-name>
<!-- Turn off productionMode (off by default). Setting productionMode=true disables
debug features. In when this is off, you can show debug window by adding ?debug to
your application URL. Always set this true in production environment. -->
<context-param>
<param-name>productionMode</param-name>
<param-value>false</param-value>
<description>Vaadin production mode</description>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<servlet>
<servlet-name>vaadin-spring</servlet-name>
<servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>com.practice.vaadin_spring.VaadinSpringDemoApplication</param-value>
<description>Vaadin application class to start</description>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>vaadin-spring</servlet-name>
<url-pattern>/vaadin/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>vaadin-spring</servlet-name>
<url-pattern>/VAADIN/*</url-pattern>
</servlet-mapping>
<!-- spring -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>spring.profiles.active</param-name>
<param-value>local</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Here is my spring main controller:
@Controller
@RequestMapping("/")
public class MainController {
@RequestMapping(value = "{jspFile}")
public String map(@PathVariable String jspFile) throws IOException {
return jspFile;
}
@RequestMapping(method = RequestMethod.GET)
public String map1() throws IOException {
return "index";
}
}
Here is working example (after fix) in github https://github.com/prilia/IntegrationSpringMvcVaadinUI
回答1:
So after some tries i've ended up with a JSP compile exception, which i believe is reasonable since you provided a test example on github. So far here's what i've done:
web.xml
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
MainController.java
@Controller
@RequestMapping("/")
public class MainController { ...
spring-servlet.xml i've added
<bean name="spring" class="org.nli.deposit.controller.MainController" />
Now seems it resolves the url:
http://localhost:8080/springMvcTest/ goes to JSPs
http://localhost:8080/springMvcTest/vaadin goes to Vaadin
it just crashes during JSP compilation, but that's a whole another question. Try on your complete project and let me know!
来源:https://stackoverflow.com/questions/27917151/how-to-integrate-old-spring-mvc-controllers-with-jsp-and-vaadin7-ui-together