Spring 启动事件
2021-07-04 本文已影响0人
我不懂我不懂a
@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...