- Create a class that extends "AbstractAnnotationConfigDispatcherServletInitializer".
- This class will be instantiated when tomcat starts.
- There are three abstract methods in this class
- getRootConfigClasses()
- Used to create Root Application Context such as Dispatcher Servlet
- getServletConfigClasses()
- Used to create Servlet Application Context.
- getServletMappings()
- Used to create URL Mappings for a servlet.
package com.springimplant.mvc.config;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class SimpleWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[]{SimpleWebConfiguration.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return null;
}
@Override
protected String[] getServletMappings() {
return new String[] {"/entry/*"};
}
}
SimpleWebContext(Dispatcher Servlet Class)
package com.springimplant.mvc.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@Configuration
@EnableWebMvc
@ComponentScan(basePackages="com.springimplant.mvc.controllers")
public class SimpleWebConfiguration {
}
No comments:
Post a Comment