有两个java配置:
@EnableWebMvc
@Configuration
public class WebConfig implements WebMvcConfigurer {
final LocaleChangeInterceptor localeInterceptor;
final LocaleResolver localeResolver;
public WebConfig(LocaleChangeInterceptor localeInterceptor , LocaleResolver localeResolver) {
this.localeInterceptor = localeInterceptor;
this.localeResolver = localeResolver;
}
...
}
@Configuration
public class I18nConfig {
@Bean
@Primary
public LocaleResolver localeResolver() {
var slr = new SessionLocaleResolver();
slr.setDefaultLocale(new Locale("en", "US"));
return slr;
}
}
问题是,如果我想让 i18n 工作,localeResolver
必须在WebConfig.java
. 但我不想把所有东西都放进去WebConfig.java
。所以我注入LocaleResolver
,WebConfig.java
然后发生以下错误。
Description:
The dependencies of some of the beans in the application context form a cycle:
┌─────┐
| webConfig defined in file [/home/xiaojie/IdeaProjects/SpringBootNote/web/mvc/build/classes/java/main/icu/kyakya/mvc/config/WebConfig.class]
↑ ↓
| org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration
└─────┘