My initializer class
public class HomeServlet extends
AbstractAnnotationConfigDispatcherServletInitializer{
@Override
protected Class>
use the configuration class as follows:
@ComponentScan(basePackages={"spittr.controllers"})
@Configuration
@EnableWebMvc
public class SpringContextConfig1 extends WebMvcConfigurerAdapter{
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
InternalResourceViewResolver ivr=new InternalResourceViewResolver();
ivr.setPrefix("/WEB-INF/jsp/");
ivr.setSuffix(".jsp");
ivr.setExposeContextBeansAsAttributes(true);
registry.viewResolver(ivr);
}
}
Basically you're extending WebMvcConfigurerAdapter
without inheriting any of its methods (in my 4.3.3 Spring version al least).
since you have a single DispatcherServlet
here, you can add the SpringContextConfig1
class to the root context and leave the servlet context empty: switch the body of the method getServletConfigClasses()
under the getRootConfigClasses()
and vice versa - see A Bit on ApplicationContext Hierarchies.
Moreover, the DispatcherServlet
mapping is more likely /
instead of /home
:
protected String[] getServletMappings() {
return new String[] {"/"};
}