整合 spring mvc 根容器和子容器
public class TestWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { //根容器 @Override protected Class<?>[] getRootConfigClasses() { return new Class<?>[]{TestRootConfig.class}; } //子容器 @Override protected Class<?>[] getServletConfigClasses() { return new Class<?>[]{TestAppConfig.class}; } //获取dispatcherservlet映射信息 //拦截所有请求 (静态资源,js,css,png) 不包括.jsp //jsp解析 是tomcat的jspy引擎解析 @Override protected String[] getServletMappings() { return new String[]{"/"}; } }
根容器
//对非controller层进入bean注入 @ComponentScan(value = "cn.qin",excludeFilters ={ @ComponentScan.Filter(type = FilterType.ANNOTATION,classes = {Controller.class}) //负责非contrller 层的扫描 },useDefaultFilters = false) public class TestRootConfig { }
子容器
@ComponentScan(value = "cn.qin",includeFilters ={ @ComponentScan.Filter(type = FilterType.ANNOTATION,classes = {Controller.class}) //负责contrllor 的扫描 },useDefaultFilters = false) public class TestAppConfig { }