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!!!!);
}
}