Skip to content

Commit

Permalink
Merge pull request #2571 from wangyu096/issue_2570
Browse files Browse the repository at this point in the history
fix: Job 后端国际化失效 #2570
  • Loading branch information
wangyu096 authored Nov 1, 2023
2 parents 1b7d36f + 1b0636e commit e20eb20
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,29 @@
* IN THE SOFTWARE.
*/

package com.tencent.bk.job.common.web.i18n;
package com.tencent.bk.job.common.web.config;

import com.tencent.bk.job.common.web.i18n.JobLangHeaderLocaleResolver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import java.util.Locale;

@Configuration
/**
* 国际化自动配置。由于需要覆盖 LocaleResolver, 所以必须比 WebMvcAutoConfiguration 先解析
*/
@Slf4j
public class I18nConfig {

@AutoConfigureBefore(WebMvcAutoConfiguration.class)
public class I18nAutoConfiguration {
@Bean("localeResolver")
@Primary
public JobLangHeaderLocaleResolver localeResolver() {
log.info("Init JobLangHeaderLocaleResolver");
JobLangHeaderLocaleResolver resolver = new JobLangHeaderLocaleResolver();
resolver.setDefaultLocale(Locale.SIMPLIFIED_CHINESE);
return resolver;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,21 @@

import com.tencent.bk.job.common.esb.metrics.EsbApiTimedAspect;
import com.tencent.bk.job.common.web.feign.FeignConfiguration;
import com.tencent.bk.job.common.web.validation.ValidationConfiguration;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Import({ActuatorSecurityConfig.class, SwaggerAdapterConfig.class, FeignConfiguration.class, FilterConfig.class})
@Import({
ActuatorSecurityConfig.class,
SwaggerAdapterConfig.class,
FeignConfiguration.class,
FilterConfig.class,
ValidationConfiguration.class
})
@Configuration(proxyBeanMethods = false)
public class WebAutoConfiguration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.ParameterNameDiscoverer;
Expand All @@ -55,12 +54,11 @@
import java.util.Locale;
import java.util.Set;

@Configuration
@Configuration(proxyBeanMethods = false)
@Slf4j
public class ValidationConfiguration {

@Bean
@Primary
@Bean("jobLocalValidatorFactoryBean")
public LocalValidatorFactoryBean localValidatorFactoryBean(
@Qualifier("messageSource") MessageSource messageSource) {
LocalValidatorFactoryBean localValidatorFactoryBean = new JobLocalValidatorFactoryBean(messageSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ com.tencent.bk.job.common.web.config.CustomTimedMetricsAutoConfiguration,\
com.tencent.bk.job.common.web.config.WebAutoConfiguration,\
com.tencent.bk.job.common.web.config.ExceptionAdviceAutoConfiguration,\
com.tencent.bk.job.common.web.config.WebInterceptorAutoConfiguration,\
com.tencent.bk.job.common.web.config.WebInterceptorRegisterAutoConfiguration
com.tencent.bk.job.common.web.config.WebInterceptorRegisterAutoConfiguration,\
com.tencent.bk.job.common.web.config.I18nAutoConfiguration

0 comments on commit e20eb20

Please sign in to comment.