如何在 util class 上加载属性

How to load properties on util class

我在 XML 上定义了我的属性文件位置,并将我的自定义实用程序 class 注册为 bean。 (工厂方法是“getInstance”)

我想要的是在我们调用自定义 util 构造之前加载我的属性值。

class AUtil
{
   private static AUtil instance;

   @Value("something")
   private m;

   private AUtil() {}

   public static AUtil() {
       if (instance == null) instance = new AUtil();

       return instance;
   }
}

我认为您应该将@PostConstruct 用作​​: 当调用构造函数时,bean 尚未初始化 - 即没有注入任何依赖项。在 @PostConstruct 方法中,bean 已完全初始化,您可以使用依赖项。