Spring web项目启动时候 加载配置程序代码

mac2025-10-28  1

spring中有: @PostConstruct @PreDestroy注解 被@PostConstruct 注解注释过的方法在加载Servle的时候运行,且只运行一次! @PreDestroy注解注释的方法在服务停止的时候运行 需要将类假如spring容器中可用@Service

@Service public class InitSo { @PostConstruct public void applicationStart(){ System.out.println(" applicationstart!!!!); } @PreDestroy public void applicationEnd(){ System.out.println(" application end!!!!); } }
最新回复(0)