Spring 启动事件

@Component
public class InitBean implements InitializingBean, ApplicationListener {

    @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 启动事件)