关于spring @postConstruct失效的问题

在定义下面这个类的时候,我定义了一个init()方法,而后用@PostConstruct方法注解,目的是为了让项目启动的时候运行此方法,初始化静态常量:java

SFtpUtil {

    String ;
    String ;
    String ;
    ;
    String ;


    init() {
        Resource resource = ClassPathResource();
        {
            Properties props = PropertiesLoaderUtils.(resource);
            = (String)props.get();
            = (String)props.get();
            = (String)props.get();
            = Integer.((String)props.get());
            = (String)props.get();
        } (IOException e) {
            .error();
            e.printStackTrace();
        }
        .info();
    }
    }

可是在容器加载以后并无运行init()方法,搞了半天,后来我在类的上面加上注解@Conponent以后就执行了,估计是spring只有在父类被声明须要加入到容器的时候才会扫描运行@PostConstruct注解的方法。可是我不是很肯定,这里先记录一下。若是有理解比较深刻的大神,望在下面留言!spring

相关文章
相关标签/搜索