Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Marking application without web.xml distributable for Tomcat session replication

I have Spring based application and using programmatic approach (AbstractAnnotationConfigDispatcherServletInitializer) for app configuration.

To make tomcat session replication work I need to 'mark' app distributable using <distributable/> tag in web.xml, however as I mentioned I am using programmatic style, e.g.

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);

        }
    }

I can't find any docs about how to do it using Spring configs, so my question here is that, Is it possible to have distributable app without having web.xml? I can't move all configs to the web.xml, so any help is appreciated.

like image 439
vtor Avatar asked May 06 '16 16:05

vtor


1 Answers

There are several option you cannot set from Java based configuration, one of them is <distributable /> another is the error-pages.

For that you still need a web.xml, just create an as empty as possible web.xml and only include <distributable />. Everything else can remain in Java based configuration.

<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>
like image 192
M. Deinum Avatar answered Sep 18 '22 02:09

M. Deinum