Spring 4 + GWT 2.6.0 + min XML配置

时间:2014-02-16 12:51:16

标签: java xml spring gwt configuration

我想使用Spring MVCGWT创建网络应用程序。主要目的是极小化XML配置。我知道如何在没有Spring MVC配置的情况下设置纯XML应用程序(使用@ConfigurationAbstractAnnotationConfigDispatcherServletInitializer而不是web.xml)但我无法弄清楚,如何实现相同与GWT。我尝试在org.spring4gwt.server.SpringGwtRemoteServiceServlet方法中添加manualy ServletContainervoid 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 {  

}

有什么想法吗?是否有可能实现这一目标?

由于

2 个答案:

答案 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=8472https://code.google.com/p/google-web-toolkit/issues/detail?id=5823 。所以现在,解决方案是使用外部服务器(如tomcat - 使用-noserver模式),但是您放弃了嵌入式Jetty的一些好处(作为开发模式)。

某些解决方案是在Tomcat(更多信息here)下的开发模式下配置Eclipse,但我没有使用它,所以我不知道这是否有效。