From 4d94ac10c68ba4a146440aad6e477438da445453 Mon Sep 17 00:00:00 2001 From: Li Shengzhao Date: Sun, 3 Apr 2016 23:13:04 +0800 Subject: [PATCH] =?UTF-8?q?(118)=20-=20Add=20java-config(=E9=9B=B6?= =?UTF-8?q?=E9=85=8D=E7=BD=AE)=20=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sos/config/MkkWebMvcConfigurer.java | 40 +++++++++++++++++++ .../sos/config/ServletInitializer.java | 2 +- .../{mkk-servlet.xml => mkk-servlet.xml.old} | 0 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/monkeyk/sos/config/MkkWebMvcConfigurer.java rename src/main/webapp/WEB-INF/{mkk-servlet.xml => mkk-servlet.xml.old} (100%) diff --git a/src/main/java/com/monkeyk/sos/config/MkkWebMvcConfigurer.java b/src/main/java/com/monkeyk/sos/config/MkkWebMvcConfigurer.java new file mode 100644 index 0000000..257531a --- /dev/null +++ b/src/main/java/com/monkeyk/sos/config/MkkWebMvcConfigurer.java @@ -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 + *

+ * 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/"); + } + +} diff --git a/src/main/java/com/monkeyk/sos/config/ServletInitializer.java b/src/main/java/com/monkeyk/sos/config/ServletInitializer.java index f73512f..a5413c4 100644 --- a/src/main/java/com/monkeyk/sos/config/ServletInitializer.java +++ b/src/main/java/com/monkeyk/sos/config/ServletInitializer.java @@ -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 diff --git a/src/main/webapp/WEB-INF/mkk-servlet.xml b/src/main/webapp/WEB-INF/mkk-servlet.xml.old similarity index 100% rename from src/main/webapp/WEB-INF/mkk-servlet.xml rename to src/main/webapp/WEB-INF/mkk-servlet.xml.old