spring [email protected]和bean执行顺序问题

很多时候我们需要在某个bean初始化时,读取一个类的属性如:spring [email protected]和bean执行顺序问题

从配置文件中获取配置使用@value,当你在bean加载时调用@value时会出现空指针异常。因为bean加载完成后才会执行@value。

方法一:写多一个配置类

spring [email protected]和bean执行顺序问题spring [email protected]和bean执行顺序问题

方法二:定义为static类型

spring [email protected]和bean执行顺序问题