学而不思则罔 思而不学则殆.|

漆原Blog

园龄:5年10个月粉丝:0关注:1

关于@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 中国大陆许可协议进行许可。

posted @   漆原Blog  阅读(548)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起