java - Spring 4 + GWT 2.6.0 + 最小 XML 配置

标签 java xml spring gwt configuration

我想使用 Spring MVCGWT 创建 Web 应用程序。主要目的是最大限度地减少 XML 配置。我知道如何在没有 XML 配置的情况下设置纯 Spring MVC 应用程序(使用 @ConfigurationAbstractAnnotationConfigDispatcherServletInitializer 而不是 web .xml),但我不知道如何使用 GWT 实现相同的目的。我尝试在 void onStartup(ServletContext container) 方法中手动添加 org.spring4gwt.server.SpringGwtRemoteServiceServletServletContainer (从 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/

相关文章:

mysql - 使用 c3p0 连接池时 MySQL 的最佳最大连接数设置是多少

java - 同时迭代 ArrayList 和 String 以执行替换正则表达式

java - 使用 HashMap 获取重复出现的情况

python - 解析 XML Python

html - hInserting line-break into XML 以便它出现在 VB.NET 中的 XSL 呈现之后

xml - 使用带有 XML 输入的 XSLT 创建具有动态元素名称的 XML 结构

Java、Spring、推送通知

Spring Boot 2.Hikari连接池优化

java - Weblogic集群401(未授权)

java - 在我的情况下使用 finalize() 吗?