dimanche 2 avril 2017

Spring (not SpringBoot) AbstractAnnotationConfigDispatcherServletInitializer

I've been searching the web for info about this subject, but I can't get to reach a satisfying conclusion. Here it goes:

I'm developing a Spring 4 (not SpringBoot) web application and I have one configuration class extending WebMvcConfigurerAdapter annotated with "@ComponentScan" to specify my beans' locations. And another class which extends of Spring's "AbstractAnnotationConfigDispatcherServletInitializer".

This is the class:

public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

@Override
protected Class[] getRootConfigClasses() {
    return new Class[] {ApplicationConfiguration.class};
}

@Override
protected Class[] getServletConfigClasses() {
    return null;
}

@Override
protected String[] getServletMappings() {
    return new String[] {"/"};
}
}

So, my doubt is: is it a good practice? Is the structure of this class acceptable? And also, how unusual is the fact that a web Java application without a "public static void main()" works?

I think that's it. Thank you for your time! Cheers.




Aucun commentaire:

Enregistrer un commentaire