Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 对Spring使用属性_Java_Spring_Properties - Fatal编程技术网

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.*”开头的