我有基于 Spring 的应用程序,并使用编程方法 ( AbstractAnnotationConfigDispatcherServletInitializer
) 进行应用程序配置。
为了使 tomcat session 复制工作,我需要“标记”应用程序 distributable使用 <distributable/>
在 web.xml
中标记,但是正如我提到的,我使用的是编程风格,例如
public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
String activeProfile = activeProfile();
if (isNotEmpty(activeProfile)) {
servletContext.setInitParameter("spring.profiles.active", activeProfile);
}
super.onStartup(servletContext);
}
}
我找不到任何关于如何使用 Spring 配置执行此操作的文档,所以我的问题是,是否可以在没有 web.xml 的情况下拥有可分发的应用程序?我无法将所有配置移至 web.xml,因此不胜感激。
最佳答案
有几个选项不能从基于 Java 的配置中设置,其中之一是 <distributable />
另一个是 error-pages
.
为此你还需要一个 web.xml
, 只需创建一个尽可能空的 web.xml
并且只包括 <distributable />
.其他一切都可以保留在基于 Java 的配置中。
<web-app
version="3.0"
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">
<distributable />
</web-app>
关于java - 将没有 web.xml 的应用程序标记为可分发以用于 Tomcat session 复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37077042/