- @Configuration
- @ComponentScan(value = "com.superdemo",includeFilters =
- @ComponentScan.Filter(type= FilterType.ANNOTATION,classes = {Controller.class})
- )
- public class SpringMVCConfiguration implements WebMvcConfigurer {
- @Override
- public void addResourceHandlers(ResourceHandlerRegistry registry) {
- WebMvcConfigurer.super.addResourceHandlers(registry);
- registry.addResourceHandler("/static.img/**").addResourceLocations("/static.img/");
- registry.addResourceHandler("/js/**").addResourceLocations("/js/");
- registry.addResourceHandler("/css/**").addResourceLocations("/css/");
- }
-
- //放行所有资源
- @Override
- public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
- WebMvcConfigurer.super.configureDefaultServletHandling(configurer);
- configurer.enable();
- }
- }
- public class ServletContainersInitConfig extends AbstractDispatcherServletInitializer {
- @Override
- protected WebApplicationContext createServletApplicationContext() {
- AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
- ctx.register(SpringMVCConfiguration.class);
- return ctx;
- }
-
- @Override
- protected String[] getServletMappings() {
- return new String[]{"/"};
- }
-
- @Override
- protected WebApplicationContext createRootApplicationContext() {
- return null;
- }
- }