1、实现ServletContextAware接口并重写其setServletContext方法
注意:该方法会在填充完普通Bean的属性,但是还没有进行Bean的初始化之前执行
2、实现ServletContextListener接口
3、将要执行的方法所在的类交个spring容器扫描(@Component),并且在要执行的方法上添加@PostConstruct注解或者静态代码块执行
4、实现ApplicationRunner接口
5、实现CommandLineRunner接口
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31558068/viewspace-2774593/ ,如需转载,请注明出处,否则将追究法律责任。