为了简化读取properties文件中的配置值,spring支持@value注解的方式来获取,这种方式大大简化了项目配置,提高业务中的灵活性。
一、两种使用方法
1、@Value("#{configProperties['key']}")
2、@Value("${key}")
二、配置
2.1 @Value("#{configProperties['key']}")使用
2.1.1配置文件:
-
配置方法1:
-
<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
-
<property name="locations">
-
<list>
-
<value>classpath:value.properties</value>
-
</list>
-
</property>
-
</bean>