I have an application in Spring and using Java Configs to configure and initialize my application, so I don't have web.xml . This is what my web initializer looks like,
public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { @Override public void onStartup(ServletContext servletContext) throws ServletException { super.onStartup(servletContext); } @Override protected Class<?>[] getRootConfigClasses() { return new Class<?>[]{PublicApiConfig.class, MobileConfig.class}; } @Override protected String[] getServletMappings() { return new String[]{"/*"}; } @Override protected Filter[] getServletFilters() { CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); LoggingFilter loggingFilter = new LoggingFilter(); return new Filter[]{characterEncodingFilter, loggingFilter}; } @Override protected Class<?>[] getServletConfigClasses() { return new Class<?>[0]; } }
I need to implement tomcat session replication, and for the purpose I need the application to be distributable . With traditional web.xml, I could add the <distributable/> attribute and that is it. However, as I understand it, this cannot be done using Java Configs.
My question is is it possible to have mixed web.xml and java configurations, for example. have
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <distributable/> </web-app>
and enable it in the WebInitializer .
source share