diff --git a/src/main/resources/modules/SpringBoot/java/config/FreeMarkerConfig.java b/src/main/resources/modules/SpringBoot/java/config/FreeMarkerConfig.java index a69d7af4..619f89fb 100644 --- a/src/main/resources/modules/SpringBoot/java/config/FreeMarkerConfig.java +++ b/src/main/resources/modules/SpringBoot/java/config/FreeMarkerConfig.java @@ -6,6 +6,7 @@ import freemarker.template.TemplateModelException; import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; import org.springframework.validation.support.BindingAwareModelMap; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @@ -29,17 +30,18 @@ import static xyz.wbsite.config.ActionConfig.SCREEN_PREFIX; @Configuration public class FreeMarkerConfig { + @Autowired + private Environment environment; @Autowired private FreeMarkerViewResolver viewResolver; @Autowired private freemarker.template.Configuration configuration; - private String suffix = ".ftl"; @PostConstruct public void setSharedVariable() throws TemplateModelException { // 全局共享变量、函数 - configuration.setSharedVariable("context", LocalData.getProp("server.servlet.context-path")); + configuration.setSharedVariable("context", environment.getProperty("server.servlet.context-path", "/")); configuration.setSharedVariable("screenHolder", new ScreenHolder()); configuration.setSharedVariable("controlHolder", new ControlHolder()); configuration.setSharedVariable("UrlUtil", new UrlUtil()); diff --git a/src/main/resources/modules/SpringBoot/java/config/SecurityConfig.java b/src/main/resources/modules/SpringBoot/java/config/SecurityConfig.java index bc75c58d..6845caf0 100644 --- a/src/main/resources/modules/SpringBoot/java/config/SecurityConfig.java +++ b/src/main/resources/modules/SpringBoot/java/config/SecurityConfig.java @@ -1,7 +1,9 @@ package ${basePackage}.config; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; import org.springframework.security.access.AccessDeniedException; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; @@ -32,10 +34,12 @@ import java.util.regex.Pattern; @Configuration @EnableGlobalMethodSecurity(securedEnabled = true) public class SecurityConfig extends WebSecurityConfigurerAdapter { + @Autowired + private Environment environment; @Override public void configure(WebSecurity web) throws Exception { - web.ignoring().mvcMatchers(LocalData.getProp("spring.mvc.static-path-pattern")); + web.ignoring().mvcMatchers(environment.getProperty("spring.mvc.static-path-pattern", "")); } @Override @@ -44,8 +48,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { .and() .addFilterBefore(new TokenFilter(), FilterSecurityInterceptor.class)// 过滤器用于处理Token .authorizeRequests() - .antMatchers(LocalData.getProp("web.url.auth.excluded")).permitAll()// 放行排除的URL - .antMatchers(LocalData.getProp("web.url.auth.included")).access("@Authorization.hasPermission(request,authentication)")// 需要权限的URL + .antMatchers(environment.getProperty("web.url.auth.excluded")).permitAll()// 放行排除的URL + .antMatchers(environment.getProperty("web.url.auth.included")).access("@Authorization.hasPermission(request,authentication)")// 需要权限的URL .and().cors() .and().headers().frameOptions().disable() .and().csrf().disable(); diff --git a/src/main/resources/modules/SpringBoot/java/config/WebMvcConfig.java b/src/main/resources/modules/SpringBoot/java/config/WebMvcConfig.java index 1916df86..007305cc 100644 --- a/src/main/resources/modules/SpringBoot/java/config/WebMvcConfig.java +++ b/src/main/resources/modules/SpringBoot/java/config/WebMvcConfig.java @@ -3,14 +3,16 @@ package ${basePackage}.config; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.util.AntPathMatcher; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; -import ${basePackage}.frame.auth.LocalData; import ${basePackage}.frame.utils.LogUtil; import javax.servlet.http.HttpServletRequest; @@ -19,6 +21,20 @@ import java.util.List; @Configuration public class WebMvcConfig implements WebMvcConfigurer { + @Autowired + private Environment environment; + + /** + * 设置忽略路径大小写 + * + * @param configurer + */ + @Override + public void configurePathMatch(PathMatchConfigurer configurer) { + AntPathMatcher matcher = new AntPathMatcher(); + matcher.setCaseSensitive(false); + configurer.setPathMatcher(matcher); + } /** * 增加全局拦截器,可用于异常日志的收集 @@ -39,7 +55,7 @@ public class WebMvcConfig implements WebMvcConfigurer { } } - }).addPathPatterns("/**").excludePathPatterns(LocalData.getProp("spring.mvc.static-path-pattern")); + }).addPathPatterns("/**").excludePathPatterns(environment.getProperty("spring.mvc.static-path-pattern")); } /** diff --git a/src/main/resources/modules/SpringBoot/java/frame/auth/LocalData.java b/src/main/resources/modules/SpringBoot/java/frame/auth/LocalData.java index cc104a83..37b25dfd 100644 --- a/src/main/resources/modules/SpringBoot/java/frame/auth/LocalData.java +++ b/src/main/resources/modules/SpringBoot/java/frame/auth/LocalData.java @@ -70,7 +70,7 @@ public class LocalData { } public static ApplicationContext getApplicationContext() { - return ${basePackage}.frame.auth.LocalData.applicationContext; + return LocalData.applicationContext; } public static void setApplicationContext(ApplicationContext applicationContext) {