Is it possible to know which JEE Container is being used during Dispatcher Servlet startup?

Asked

Viewed 73 times

3

After some difficulties with the use of the Spring Security and JBoss using annotations based on API Servlet 3 (Servlet 3.1 more specifically), I discovered that when using Spring with JBoss, in particular Jboss EAP 6.1+, the mapping of the Dispacher Servlet to the URL "/" simply, it is necessary that such mapping be done to the URL "/*".

To solve such problem I even created a Fork to study such problem, and this is found in the link: https://github.com/carlosdelfino/spring-security/tree/rb4.0.1.RELEASE-JBoss-patch-1, where I have already tested the example "Insecure MVC" and such correction solves the problem.

But I am developing an application that will be executed in several containers, and I’m afraid I may have problems with other resources, so I need to parameterize the Servlet startup.

In this case the Spring offers me some resource to identify which container is running in?

How to do this?

  • This problem is related to: http://answall.com/questions/68110/qual-a-programa%C3%A7%C3%A3o-should-be-made-to-use-the-spring-security-com-jboss-com-anot

1 answer

5


You can create a class to boot the Webapp that implements the interface WebApplicationInitializer.

This interface has a single method that receives a ServletContext and by ServletContext you can get the server name.

public class WebAppInitializer implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext context) throws ServletException {
        System.out.println(context.getServerInfo());
    }

}

Console output:

Tomcat

WildFly

  • Adelmo, perfect worked, as I’m using the class AbstractAnnotationConfigDispatcherServletInitializer, I superimposed the method and called the super, it worked perfectly. https://www.dropbox.com/s/g8v49v91olo3of5/Captura%20de%20de%20tela%202015-07-10%2015.04.58.png? dl=0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.