关于@PostConstruct 注解
@PostConstruct注解,好多人以为是Spring提供的。其实是Java自己的注解。
import javax.annotation.PostConstruct;
Java中该注解的说明:@PostConstruct该注解被用来修饰一个非静态的void()方法。被@PostConstruct修饰的方法会在服务器加载Servlet时运行,并且只会被服务器运行一次,类似Servlet的init()方法。被@PostConstruct修饰的方法会在构造函数之后,init()方法前运行。
通常我们会在Spring中使用到该注解,该注解的方法在整个Bean初始化中的执行顺序如下:
Constructor(构造方法) -> @Autowired(依赖注入) -> @PostConstruct(注释的方法)
如下代码用于在SpringBoot启动过程中设置系统属性:
package com.ylja.config;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
/**
* @description: springboot启动时设置cxf运行系统参数
* @author: wanglp
* @create: 2020-06-21 22:03
*/
@Component
public class YljaCxfPropertiesConstruct {
@PostConstruct
public void doConstruct() throws Exception {
System.setProperty("org.apache.cxf.stax.allowInsecureParser","1");
}
}
本文作者:漆原Blog
本文链接:https://www.cnblogs.com/7moon/p/13679097.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步