(118) - Add java-config(零配置) 的支持

2.0.0
Li Shengzhao 2016-04-03 23:13:04 +08:00
parent d34b48138c
commit 4d94ac10c6
3 changed files with 41 additions and 1 deletions

View File

@ -0,0 +1,40 @@
package com.monkeyk.sos.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
/**
* 2016/4/3
* <p/>
* Replace mkk-servlet.xml
*
* @author Shengzhao Li
*/
@Configuration
@EnableWebMvc
public class MkkWebMvcConfigurer extends WebMvcConfigurerAdapter {
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/jsp/");
viewResolver.setSuffix(".jsp");
registry.viewResolver(viewResolver);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/index.jsp*").addResourceLocations("/index.jsp");
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
}

View File

@ -28,7 +28,7 @@ public class ServletInitializer extends AbstractAnnotationConfigDispatcherServle
@Override
protected Class<?>[] getServletConfigClasses() {
throw new UnsupportedOperationException("Not yet implemented");
return new Class[]{MkkWebMvcConfigurer.class};
}
@Override