Java 对Spring使用属性
我的属性文件中几乎没有像这样的属性Java 对Spring使用属性,java,spring,properties,Java,Spring,Properties,我的属性文件中几乎没有像这样的属性 dataCenterOptions.host="xyz" dataCenterOptions.user="abc" dataCenterOptions.password="def" dataCenterOptions.port="ghi" 我在我的Spring类中使用它,用@Value注释它。但是,我可以用一个变量来访问以下每个变量,而不是创建四个单独的变量。差不多 @Value("${dataCenterOptions}") Properties data
dataCenterOptions.host="xyz"
dataCenterOptions.user="abc"
dataCenterOptions.password="def"
dataCenterOptions.port="ghi"
我在我的Spring类中使用它,用@Value
注释它。但是,我可以用一个变量来访问以下每个变量,而不是创建四个单独的变量。差不多
@Value("${dataCenterOptions}")
Properties dataCenterProps;
我该怎么做呢?一种方法是
At代码
@Resource(name="prop")
Properties prop;
在配置文件中
<util:properties id="prop" location="properties/dataCenterOptions.properties" />
但这将获得该属性变量中的所有属性。我只需要那些以“dataCenterOptions.*”开头的