Spring怎么让外豆压倒内豆?

kuhbmx9i  于 2021-07-16  发布在  Java
关注(0)|答案(0)|浏览(293)

有两种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
└─────┘

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题