gpt4 book ai didi

java - 使用 Google 应用程序引擎进行 Spring Bootstrapping

转载 作者:行者123 更新时间:2023-12-01 10:45:39 25 4
gpt4 key购买 nike

我当前正在初始化一个没有任何 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 并让它指向这个初始值设定项吗?

最佳答案

它不适用于 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

关于java - 使用 Google 应用程序引擎进行 Spring Bootstrapping,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34192849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com