我知道这可能看起来像以前提出的问题,但我在这里面临不同的问题。
我有一个只有静态方法的实用程序类。我没有,我也不会从中举一个例子。
public class Utils{
private static Properties dataBaseAttr;
public static void methodA(){
}
public static void methodB(){
}
}
现在我需要 Spring 用数据库属性 Properties.Spring 配置填充 dataBaseAttr 是:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<util:properties id="dataBaseAttr"
location="file:#{classPathVariable.path}/dataBaseAttr.properties" />
</beans>
我已经在其他 bean 中完成了它,但是这个类(Utils)中的问题不是 bean,如果我把它变成一个 bean,我仍然无法使用该变量,因为该类不会被实例化并且总是变量等于空。