content: /*
   * 爱组搭，低代码组件化开发平台
   * ------------------------------------------
   * 受知识产权保护，请勿删除版权申明，开发平台不允许做非法网站，后果自负
   */
  package com.aizuda.boot.config;
  
  import jakarta.annotation.Resource;
  import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.core.env.Environment;
  import org.springframework.http.converter.HttpMessageConverter;
  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.List;
  
  
  /**
   * WEB 初始化相关配置
   *
   * @author 青苗
   * @since 1.0.0
   */
  @ControllerAdvice
  @Configuration
  public class BootConfigurer implements WebMvcConfigurer {
      @Resource
      private HttpMessageConverters jacksonHttpMessageConverters;
      @Resource
      private Environment environment;
  
      @Bean
      public LocaleResolver localeResolver() {
          CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver();
          // 多语言 cookie 名称设置
          cookieLocaleResolver.setCookieName("locale");
          return cookieLocaleResolver;
      }
  
      @Override
      public void addInterceptors(InterceptorRegistry registry) {
          // i18n 多语言拦截处理器
          registry.addInterceptor(new LocaleChangeInterceptor()).addPathPatterns("/**");
      }
  
      @Override
      public void addCorsMappings(CorsRegistry registry) {
          registry.addMapping("/**")
                  .allowedMethods("GET", "POST", "OPTIONS")
                  .allowCredentials(true)
                  .maxAge(3600)
                  .allowedOriginPatterns("*")
                  .allowedHeaders("*");
      }
  
      @Override
      public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
          converters.clear();
          converters.addAll(jacksonHttpMessageConverters.getConverters());
      }
  
  }
  