我是靠谱客的博主 含糊翅膀,这篇文章主要介绍[Spring boot] CommandLineRunner and Autowired,现在分享给大家,希望可以做个参考。

Previously we use Application Context to get Bean and Dependenies injection. It is actually easier to use 'CommonLineRunner'.

Main beneift is we can use @Autowired.

 

@SpringBootApplication
public class SpringAopApplication implements CommandLineRunner{
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private Business1 business1;
@Autowired
private Business2 business2;
public static void main(String[] args) {
SpringApplication.run(SpringAopApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
logger.info(business1.calculateSomething());
logger.info(business2.calculateSomething());
}
}

 

转载于:https://www.cnblogs.com/Answer1215/p/10865277.html

最后

以上就是含糊翅膀最近收集整理的关于[Spring boot] CommandLineRunner and Autowired的全部内容,更多相关[Spring内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(144)

评论列表共有 0 条评论

立即
投稿
返回
顶部