Java 春季4&x2B;GWT 2.6.0+;最小XML配置
我想使用Java 春季4&x2B;GWT 2.6.0+;最小XML配置,java,xml,spring,gwt,configuration,Java,Xml,Spring,Gwt,Configuration,我想使用springmvc和GWT创建web应用程序。主要目的是将XML配置最小化。我知道如何在没有XML配置的情况下设置纯springmvc应用程序(使用@configuration和AbstractAnnotationConfigDispatcherServletInitializer而不是web.XML),但我不知道如何使用GWT实现同样的效果。我试图在void onStartup(ServletContext container)方法中将手动org.spring4gwt.server.S
springmvc
和GWT
创建web应用程序。主要目的是将XML
配置最小化。我知道如何在没有XML
配置的情况下设置纯springmvc
应用程序(使用@configuration
和AbstractAnnotationConfigDispatcherServletInitializer
而不是web.XML),但我不知道如何使用GWT
实现同样的效果。我试图在void onStartup(ServletContext container)
方法中将手动org.spring4gwt.server.SpringGwtRemoteServiceServlet
添加到ServletContainer
中的void onStartup(ServletContext container)
中,但应用程序似乎忽略了我的类WebAppStarter
扩展AbstractAnnotationConfigDispatcherServletInitializer
(我只是将syser放在WebAppStarter
的构造函数中,在纯Spring MVC
应用程序中,它在标准err上打印一些内容,但在GWT
中,标准err上没有打印任何内容)
以下是我的配置:
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 {
}
公共类WebAppStarter扩展了AbstractAnnotationConfigDispatcherServletInitializer{
公共WebAppStarter(){
System.err.println(“======================>WEB应用程序启动程序”);
}
@凌驾
受保护类[]getRootConfigClasses(){
返回新类[0];
}
@凌驾
受保护类[]getServletConfigClasses(){
返回新类[]{WebAppConfiguration.Class};
}
@凌驾
受保护的字符串[]getServletMappings(){
返回新字符串[]{”/“};
}
@凌驾
启动时公共void(ServletContext容器)引发ServletException{
超级启动(集装箱);
ServletRegistration.DynamicTestServlet=container.addServlet(“gwtServlet”,新的SpringWTremoteServiceServlet());
addMapping(“/TestModule/springGwtServices/*”);
}
}
@配置
@EnableWebMvc
@组件扫描(基本\u弹簧\u组件\u扫描\u包\u名称)
公共类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>
有什么想法吗?有可能实现吗
谢谢看起来您已经熟悉了编写SpringMVC控制器(例如,或)
然后在一个单独的UI项目中,您可以与这些服务进行交互(例如)。经过一些搜索,现在看来,
GWT
SDK中嵌入的Jetty
配置不支持Servlet 3.0
web.xml-less配置。我发现了以下问题:以及
因此,目前的解决方案是使用外部服务器(如tomcat
-使用-noserver
模式),但您失去了嵌入式Jetty
的一些好处(作为开发模式)
一些解决方案是在
Eclipse
下的开发模式下配置Tomcat
(更多信息),但我没有使用它,所以我不知道这是否有效。这可能没有帮助。但您是否考虑过不与服务/控制器共同部署UI?而是让GWT项目通过REST调用进行交互,可以是w/RequestBuilder,也可以是w/RestyGwt?老实说,我不知道这种方法是如何工作的(通过REST).对我来说,用Java(而不是JavaScript)编写UI很重要。这个解决方案支持这个吗?