抓住spring初始化所有豆子的时刻

我有春季申请(我没有懒豆)。

我想在初始化所有@Component(@Repositoey @Service @Controller)bean时插入逻辑。

我该怎么做?

正如在这个问题的答案中提到的,您可以使用ApplicationListener并查找ContextRefreshedEvent :

public class Loader implements ApplicationListener{ public void onApplicationEvent(ContextRefreshedEvent event) { // whatever you want to do when app context is initialized or refreshed } }