@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();
    }

}

 

posted @ 2020-08-03 19:03  yangxiaohui227  阅读(3138)  评论(0编辑  收藏  举报