|
@@ -5,11 +5,19 @@
|
|
|
*/
|
|
|
package com.aizuda.boot.config;
|
|
|
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
+import org.springframework.core.env.Environment;
|
|
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
|
+import org.springframework.web.servlet.LocaleResolver;
|
|
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
+import org.springframework.web.servlet.i18n.CookieLocaleResolver;
|
|
|
+import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
|
|
|
+
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -21,12 +29,25 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
@ControllerAdvice
|
|
|
@Configuration
|
|
|
public class BootConfigurer implements WebMvcConfigurer {
|
|
|
+ @Resource
|
|
|
+ private Environment environment;
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public LocaleResolver localeResolver() {
|
|
|
+ CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver();
|
|
|
+ // 多语言 cookie 名称设置
|
|
|
+ cookieLocaleResolver.setCookieName("locale");
|
|
|
+ return cookieLocaleResolver;
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public void addInterceptors(InterceptorRegistry registry) {
|
|
|
-// BlockMethodHandlerInterceptor interceptor = new BlockMethodHandlerInterceptor();
|
|
|
-// InterceptorRegistration registration = registry.addInterceptor(interceptor);
|
|
|
-// registration.addPathPatterns("/**");
|
|
|
+ // 演示环境阻止执行拦截器
|
|
|
+ if (Objects.equals("pro", environment.getProperty("spring.profiles.active"))) {
|
|
|
+ registry.addInterceptor(new BlockHandlerInterceptor()).addPathPatterns("/sys/**");
|
|
|
+ }
|
|
|
+ // i18n 多语言拦截处理器
|
|
|
+ registry.addInterceptor(new LocaleChangeInterceptor()).addPathPatterns("/**");
|
|
|
}
|
|
|
|
|
|
@Override
|