美文网首页
Spring 启动事件

Spring 启动事件

作者: 我不懂我不懂a | 来源:发表于2021-07-04 21:30 被阅读0次
@Component
public class InitBean implements InitializingBean, ApplicationListener<ApplicationReadyEvent> {

    @Autowired
    HelloService helloService;

    public InitBean() {
        System.out.println("init initBean.");
    }

    @PostConstruct
    public void init() {
        helloService.hello();
        System.out.println("post construct....");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("after properties set...");
    }

    @Override
    public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
        System.out.println("ready event...");
    }
}

output:
init initBean.
hello service....
post construct....
after properties set...
ready event...

相关文章

网友评论

      本文标题:Spring 启动事件

      本文链接:https://www.haomeiwen.com/subject/owyvultx.html