我想使用 Spring MVC
和 GWT
创建 Web 应用程序。主要目的是最大限度地减少 XML
配置。我知道如何在没有 XML
配置的情况下设置纯 Spring MVC
应用程序(使用 @Configuration
和 AbstractAnnotationConfigDispatcherServletInitializer
而不是 web .xml),但我不知道如何使用 GWT
实现相同的目的。我尝试在 void onStartup(ServletContext container)
方法中手动添加 org.spring4gwt.server.SpringGwtRemoteServiceServlet
到 ServletContainer
(从 AbstractAnnotationConfigDispatcherServletInitializer 覆盖)
),但应用程序似乎忽略了我的类 WebAppStarter
扩展 AbstractAnnotationConfigDispatcherServletInitializer
(我只是将 syser 放在 WebAppStarter
的构造函数中 - 纯粹Spring MVC
应用程序会在标准错误上打印一些内容,但使用 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 {
}
我没有 applicationContext.xml。
web.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 Controller 的编写(例如 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 )。
关于java - Spring 4 + GWT 2.6.0 + 最小 XML 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21811347/