@DependsOn注解的使用

如果Bean A 在创建前需要先创建BeanB此时就可以使用DependsOn注解

@Configuration
public class MyConfig {
    @Bean
    @DependsOn("apple")
    public Student student(){
        System.out.println("我是student");
        return new Student();
    }
    @Bean
    public Apple apple(){
        System.out.println("我是apple");
        return new Apple();
    }

}
原文地址:https://www.cnblogs.com/yangxiaohui227/p/13428096.html