我想使用Spring MVC
和GWT
创建网络应用程序。主要目的是极小化XML
配置。我知道如何在没有Spring MVC
配置的情况下设置纯XML
应用程序(使用@Configuration
和AbstractAnnotationConfigDispatcherServletInitializer
而不是web.xml)但我无法弄清楚,如何实现相同与GWT
。我尝试在org.spring4gwt.server.SpringGwtRemoteServiceServlet
方法中添加manualy ServletContainer
到void onStartup(ServletContext container)
(从AbstractAnnotationConfigDispatcherServletInitializer
覆盖),但似乎应用程序忽略我的类WebAppStarter
扩展{{1} (我只是将syser放在AbstractAnnotationConfigDispatcherServletInitializer
的构造函数中 - 在纯WebAppStarter
应用程序中,它在标准错误上打印一些内容,但是使用Spring MVC
- 标准错误上没有打印出来。)
以下是我的配置:
GWT
我没有applicationContext.xml。
的web.xml:
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 {
}
有什么想法吗?是否有可能实现这一目标?
由于
答案 0 :(得分:0)
看起来您已经熟悉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)。
答案 1 :(得分:0)
经过一些搜索,看起来(现在)Jetty
SDK中的嵌入式GWT
配置不支持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
的一些好处(作为开发模式)。
某些解决方案是在Tomcat
(更多信息here)下的开发模式下配置Eclipse
,但我没有使用它,所以我不知道这是否有效。