From d8c287189124e853a49109141f8f4a7f3190b9b5 Mon Sep 17 00:00:00 2001 From: monkeyk7 Date: Tue, 5 Dec 2017 21:59:43 +0800 Subject: [PATCH] Update config --- .../monkeyk/sos/config/ContextConfigurer.java | 45 ----------- .../sos/config/ServletInitializer.java | 78 ------------------- .../monkeyk/sos/config/WebMvcConfigurer.java | 42 ---------- .../sos/config/WebSecurityConfigurer.java | 6 +- src/main/resources/application.properties | 16 +++- 5 files changed, 16 insertions(+), 171 deletions(-) delete mode 100644 src/main/java/com/monkeyk/sos/config/ContextConfigurer.java delete mode 100644 src/main/java/com/monkeyk/sos/config/ServletInitializer.java delete mode 100644 src/main/java/com/monkeyk/sos/config/WebMvcConfigurer.java diff --git a/src/main/java/com/monkeyk/sos/config/ContextConfigurer.java b/src/main/java/com/monkeyk/sos/config/ContextConfigurer.java deleted file mode 100644 index 1aaad46..0000000 --- a/src/main/java/com/monkeyk/sos/config/ContextConfigurer.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.monkeyk.sos.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.datasource.DataSourceTransactionManager; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -import javax.sql.DataSource; - -/** - * 2016/4/4 - *

- * Replace context.xml, transaction.xml - * - * @author Shengzhao Li - */ -@Configuration -@ComponentScan(basePackages = "com.monkeyk.sos") -//@PropertySource(value = {"classpath:spring-oauth-server.properties"}) -@EnableTransactionManagement() -public class ContextConfigurer { - - - - - - - @Bean(name = "transactionManager") - public PlatformTransactionManager transactionManager(DataSource dataSource) { - DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(); - transactionManager.setDataSource(dataSource); - return transactionManager; - } - - - @Bean(name = "jdbcTemplate") - public JdbcTemplate jdbcTemplate(DataSource dataSource) { - return new JdbcTemplate(dataSource); - } - - -} diff --git a/src/main/java/com/monkeyk/sos/config/ServletInitializer.java b/src/main/java/com/monkeyk/sos/config/ServletInitializer.java deleted file mode 100644 index 5e666d1..0000000 --- a/src/main/java/com/monkeyk/sos/config/ServletInitializer.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.monkeyk.sos.config; - -import com.monkeyk.sos.web.filter.CharacterEncodingIPFilter; -import org.springframework.web.filter.DelegatingFilterProxy; -import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; -import org.springframework.web.util.Log4jConfigListener; - -import javax.servlet.ServletContext; -import javax.servlet.ServletException; - -/** - * 2016/4/3 - *

- * Config DispatchServlet - *

- * Replace web.xml - * - * @author Shengzhao Li - */ -public class ServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { - - - @Override - protected String[] getServletMappings() { - return new String[]{"/"}; - } - - - @Override - public void onStartup(ServletContext servletContext) throws ServletException { - super.onStartup(servletContext); - -// servletContext.setAttribute("webAppRootKey", "spring-oauth-server"); - servletContext.setInitParameter("webAppRootKey", "spring-oauth-server"); -// servletContext.setInitParameter("contextConfigLocation", "classpath:spring/*.xml"); - servletContext.setInitParameter("log4jConfigLocation", "/WEB-INF/log4j.xml"); - - //Add Filters - - CharacterEncodingIPFilter characterEncodingIPFilter = new CharacterEncodingIPFilter(); - characterEncodingIPFilter.setEncoding("UTF-8"); - characterEncodingIPFilter.setForceEncoding(true); - servletContext.addFilter("encodingFilter", characterEncodingIPFilter).addMappingForUrlPatterns(null, false, "/*"); - - DelegatingFilterProxy securityFilter = new DelegatingFilterProxy("springSecurityFilterChain"); - servletContext.addFilter("springSecurityFilterChain", securityFilter).addMappingForUrlPatterns(null, false, "/*"); - -// SiteMeshFilter siteMeshFilter = new SiteMeshFilter(); -// servletContext.addFilter("sitemesh", siteMeshFilter).addMappingForUrlPatterns(null, false, "/*"); - - //Add Listeners - - servletContext.addListener(Log4jConfigListener.class); - - } - -// @Override -// protected WebApplicationContext createRootApplicationContext() { -// return createServletApplicationContext(); -// } -// -// @Override -// protected WebApplicationContext createServletApplicationContext() { -// AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); -// context.scan(ClassUtils.getPackageName(getClass())); -// return context; -// } - - @Override - protected Class[] getRootConfigClasses() { - return new Class[]{ContextConfigurer.class, WebSecurityConfigurer.class, OAuth2ServerConfig.class}; - } - - @Override - protected Class[] getServletConfigClasses() { - return new Class[]{WebMvcConfigurer.class}; - } -} diff --git a/src/main/java/com/monkeyk/sos/config/WebMvcConfigurer.java b/src/main/java/com/monkeyk/sos/config/WebMvcConfigurer.java deleted file mode 100644 index 122c5f6..0000000 --- a/src/main/java/com/monkeyk/sos/config/WebMvcConfigurer.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.monkeyk.sos.config; - -import org.springframework.context.annotation.ComponentScan; -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 -@ComponentScan(basePackages = {"com.monkeyk.sos.web"}) -public class WebMvcConfigurer 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/WebSecurityConfigurer.java b/src/main/java/com/monkeyk/sos/config/WebSecurityConfigurer.java index 756475a..8c40c7c 100644 --- a/src/main/java/com/monkeyk/sos/config/WebSecurityConfigurer.java +++ b/src/main/java/com/monkeyk/sos/config/WebSecurityConfigurer.java @@ -65,11 +65,7 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter { web.expressionHandler(new OAuth2WebSecurityExpressionHandler()); } - @Override - @Bean(name = "authenticationManager") - public AuthenticationManager authenticationManagerBean() throws Exception { - return super.authenticationManagerBean(); - } + @Override diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 50dbe90..1022c0e 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -8,5 +8,19 @@ spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/oauth2?autoReconnect=true&autoReconnectForPools=true&useUnicode=true&characterEncoding=utf8 spring.datasource.data-username=andaily spring.datasource.data-password=andaily - +# +#THYMELEAF +# +spring.thymeleaf.prefix=/WEB-INF/view/ +spring.thymeleaf.suffix=.html +spring.thymeleaf.mode=HTML5 +spring.thymeleaf.encoding=UTF-8 +# ;charset= is added +spring.thymeleaf.content-type=text/html +# set to false for hot refresh +spring.thymeleaf.cache=false +# +# Logging +# +logging.level.root=INFO