1、cf-gateway locale透传修复;2、LocaleResolver修改为全局web服务配置;

This commit is contained in:
gaoqr
2026-05-13 11:45:03 +08:00
parent db2e31680c
commit 8438563147
5 changed files with 45 additions and 34 deletions
@@ -4,6 +4,8 @@ import com.cf.imes.framework.common.exception.enums.ServiceErrorCodeRange;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Locale;
/**
* 业务逻辑异常 Exception
*/
@@ -22,6 +24,8 @@ public final class ServiceException extends RuntimeException {
*/
private String message;
private Locale locale;
/**
* 占位参数
*/
@@ -44,6 +48,19 @@ public final class ServiceException extends RuntimeException {
this.message = message;
}
public ServiceException(ErrorCode errorCode, Locale locale, Object... args) {
this.code = errorCode.getCode();
this.locale = locale;
this.message = errorCode.getMsg();
this.args = args;
}
public ServiceException(Integer code, Locale locale, String message) {
this.code = code;
this.locale = locale;
this.message = message;
}
public Integer getCode() {
return code;
}
@@ -24,11 +24,15 @@ import org.springframework.web.client.RestTemplate;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import jakarta.annotation.Resource;
import jakarta.servlet.Filter;
import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;
import java.util.Locale;
@AutoConfiguration
@EnableConfigurationProperties(WebProperties.class)
@@ -60,6 +64,13 @@ public class ChenfengWebAutoConfiguration implements WebMvcConfigurer {
&& antPathMatcher.match(api.getController(), clazz.getPackage().getName())); // 仅仅匹配 controller 包
}
@Bean
public LocaleResolver localeResolver() {
AcceptHeaderLocaleResolver resolver = new AcceptHeaderLocaleResolver();
resolver.setDefaultLocale(Locale.SIMPLIFIED_CHINESE);
return resolver;
}
@Bean
public I18nUtils i18nUtils(MessageSource messageSource) {
return new I18nUtils(messageSource);