【问题标题】:Spring Bootstrapping with Google Application Engine使用 Google 应用程序引擎进行 Spring Bootstrapping
【发布时间】:2015-12-10 02:45:21
【问题描述】:

我目前正在初始化一个没有任何 web.xml 的 Web 应用程序。我正在引导 Spring AbstractAnnotationConfigDispatcherServletInitializer 如下:

public class SpringMvcInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[] { SpringRootConfig.class };
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[] { ThymeleafConfig.class };
    }

    @Override
    protected String[] getServletMappings() {
        return new String[] { "/" };
    }

    @Override 
    protected Filter[] getServletFilters() {
        return new Filter[] {new EmailVerificationFilter()};
    }
}

我现在正尝试将此应用程序“移植”到 Google App Engine 中。但是 GAE 需要 web.xml。有什么办法可以创建一个 web.xml 并让它指向这个初始化程序?

【问题讨论】:

    标签: java spring google-app-engine web.xml


    【解决方案1】:

    它不适用于 Google Appengine。 AbstractAnnotationConfigDispatcherServletInitializer 需要 Servlet 3.0 环境,但 Appengine 仅支持版本 2.5

    因此,您必须为 servlet 和过滤器使用 web.xml 配置。但是您也可以从那里注册Configuration 课程。通过将它们传递给DispatcherServlet,例如:

    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
        <init-param>
            <param-name>contextClass</param-name>
            <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
        </init-param>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>SpringRootConfig</param-value>
        </init-param>
    </servlet>
    

    PS 还有关于 Servlet 3.0 支持的问题 - https://code.google.com/p/googleappengine/issues/detail?id=3091

    【讨论】:

      猜你喜欢
      • 2010-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多