Error creating bean with name 'wordContext': Requested bean is currently in creation: Is there an unresolvable circular reference?
@DependsOn
注解
Beans on which the current bean depends. Any beans specified are guaranteed to be created by the container before this bean.
Used infrequently in cases where a bean does not explicitly depend on another through properties or constructor arguments, but rather depends on the side effects of another bean’s initialization.
May be used on any class directly or indirectly annotated with org.springframework.stereotype.Component or on methods annotated with Bean.
Using DependsOn at the class level has no effect unless component-scanning is being used. If a DependsOn-annotated class is declared via XML, DependsOn annotation metadata is ignored, and is respected instead.
/**
* @author Tany
* @Description X
* @email <a href="5824519@qq.com">5824519@qq.com</a>
* @createTime 2021/8/26
*/
@Component
public class WordsConfig {
@Bean
public WordContext wordContext() {
return new WordContext();
}
@Bean
@DependsOn({"wordContext"})
public WordFilter wordFilter(@Autowired WordContext wordContext) {
return new WordFilter(wordContext);
}
}