public class LogUtil {
@Autowired
private LogService logService;
private static LogUtil logUtil;
@PostConstruct
public void init() {
logUtil = this;
logUtil.logService = this.logService;
}
//之后调用
logUtil.logService.xxx();
}
@PostConstruct被@PostConstruct修饰的方法会在服务器加载Servlet的时候运行,并且只会被服务器调用一次,类似于Servlet的init()方法。
被@PostConstruct修饰的方法会在构造函数之后,init()方法之前执行。
@PreConstruct
被PreConstruct修饰的方法会在服务器卸载Servlet的时候运行,并且只会被服务器调用一次,类似于Servlet的destroy()方法。被@PreConstruct修饰的方法会在destroy()方法之后运行,在Servlet被彻底卸载以前。