使用spring util读取属性文件。
<?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:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util" xmlns:mongo="http://www.springframework.org/schema/data/mongo" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd"> <context:annotation-config /> <util:properties id="db_config" location="classpath:db_config.properties"></util:properties></beans>
用户使用新的’@value’批注获取属性文件key = value,即
示例:db_config.properties包含db_user_name = uttesh db_password =密码
要获取“ db.user.name”属性值,请使用以下代码
@Value("#{db_config[db_user_name]}")private String dbUsername;


