我想使用Spring MVC
和GWT
创建Web应用程序。主要目的是极小XML
配置。我知道如何在没有XML
配置的情况下设置纯Spring MVC
应用程序(使用 @Configuration
和 AbstractAnnotationConfigDispatcherServletInitializer
而不是 web.xml),但我无法弄清楚如何用 GWT
实现相同的目标。我尝试在方法中添加手动org.spring4gwt.server.SpringGwtRemoteServiceServlet
到void onStartup(ServletContext container)
方法中的ServletContainer
(从 AbstractAnnotationConfigDispatcherServletInitializer
覆盖),但似乎应用程序在扩展AbstractAnnotationConfigDispatcherServletInitializer
WebAppStarter
忽略了我的类(我只是将 syser 放在 WebAppStarter
的构造函数中 - 在纯Spring MVC
应用程序中,它会在标准 err 上打印一些内容,但有了GWT
- 标准错误上没有打印任何内容)。
以下是我的配置:
public class WebAppStarter extends AbstractAnnotationConfigDispatcherServletInitializer {
public WebAppStarter() {
System.err.println("======================> WEB_APP_STARTER");
}
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[0];
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[] { WebAppConfiguration.class };
}
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
@Override
public void onStartup(ServletContext container) throws ServletException {
super.onStartup(container);
ServletRegistration.Dynamic testServlet = container.addServlet("gwtServlet", new SpringGwtRemoteServiceServlet());
testServlet.addMapping("/TestModule/springGwtServices/*");
}
}
@Configuration
@EnableWebMvc
@ComponentScan(BASE_SPRING_COMPONENT_SCAN_PACKAGE_NAME)
public class WebAppConfiguration {
}
我没有应用程序上下文.xml。
网站.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
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_0.xsd"
version="3.0">
</web-app>
有什么想法吗?有可能实现吗?
谢谢
看起来你已经熟悉编写Spring MVC控制器(例如 https://spring.io/guides/gs/rest-service/或 http://xpadro.blogspot.com/2014/01/migrating-spring-mvc-restful-web.html?m=1)。
然后在单独的UI项目中,您可以与这些服务进行交互(例如 http://wpamm.blogspot.com/2013/07/gwt-and-rest-part-2-client-restygwt.html?m=1)。
经过一番搜索,看起来(目前)SDK GWT
中嵌入Jetty
配置不支持Servlet 3.0
无 Web .xml配置。我发现了这些问题:https://code.google.com/p/google-web-toolkit/issues/detail?id=8472 和 https://code.google.com/p/google-web-toolkit/issues/detail?id=5823.所以现在的解决方案是使用外部服务器(如tomcat
- 使用-noserver
模式),但你失去了嵌入式Jetty
的一些好处(作为开发模式)。
一些解决方案是在Eclipse
下以开发模式配置Tomcat
(更多信息在这里),但我没有使用它,所以我不知道这是否有效。