关于spring @postConstruct失效的问题

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

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,springMVC,@PostConstruct)