/** * 配置文件选择性注入bean * #development tool plugin * devtool: * bean: * injection: true */ @Slf4j @Configuration public class ConfigurationInjection { //注入的bean对象 @Bean @ConditionalOnProperty(prefix = "devtool", name = "bean.injection", havingValue = "true",matchIfMissing = false) public CommandLineRunner commandLineRunner(ApplicationContext ac) { return args -> { log.info("注入的bean对象:"); String[] beanNames = ac.getBeanDefinitionNames(); Arrays.sort(beanNames); for (String beanName : beanNames) { log.info(beanName); } int count = ac.getBeanDefinitionCount(); log.info("注入了{}个bean对象",count); }; } }
打印spring注入的对象
最新推荐文章于 2024-04-27 09:13:51 发布