Anthony
Anthony

Reputation: 191

Why is WebApplicationInitializer ignored?

I have a Web application (war) built with maven. I'm using an old struts application (no choice). I'm refactoring old services with spring annotation using AnnotationConfigApplicationContext and a configuration class.

I use JBoss AS 7.0.1.

I need to implement web services in my application. So I'm trying to set DispatcherServlet using WebApplicationInitializer.

I've tried by implemeting, "WebApplicationInitializer", or extending "AbstractDispatcherServletInitializer", "AbstractAnnotationConfigDispatcherServletInitializer", but class is not detected and processed once JBoss is started and war is deployed.

How does Jboss to detect this type of class. Do we have to set a declaration somewhere.

sample code of my last try :

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer   {

    @Override
    protected Class<?>[] getRootConfigClasses() {
        String test = "";
        test.toLowerCase();
        return null;
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        String test = "";
        test.toLowerCase();
        return new Class[] {ApplicationContextConfiguration.class};
    }

    @Override
    protected String[] getServletMappings() {
        String test = "";
        test.toLowerCase();
        return new String[] {
                "*.html"
                ,"*.json" };
    }

} 

Upvotes: 1

Views: 850

Answers (1)

Anthony
Anthony

Reputation: 191

FOUND.

To detect the "WebApplicationInitializer" implementation. Add the file : /META-INF/services/javax.servlet.ServletContainerInitializer Set this file in a JAR

Set in the full packagge and class name : com.xxxxxxx.AbstractAnnotationConfigDispatcherServletInitializer

Spring implements the ServletContainerInitializer through SpringServletContainerInitializer class. Per the Servlet specs, this implementation must be declared in a META-INF/services/javax.servlet.ServletContainerInitializer file of the libraries jar file - Spring declares this in spring-web*.jar jar file and has an entry org.springframework.web.SpringServletContainerInitializer

Upvotes: 1

Related Questions