在applicationContext.xml中加入:
1:在配置为:
<util:properties id="APP_PROPERTIES" location="classpath:application.properties" local-override="true"/>
或:
<util:properties id="APP_PROPERTIES"> <prop key="testKey">testValue</prop> </util:properties>
时: 在字段/参数/方法中使用为:
@Value("#{APP_PROPERTIES['testKey']}") String testValue;
2:
在配置为:
<bean id="APP_PROPS" class="java.util.Properties"> <constructor-arg index="0"> <props> <prop key="testKey">testValue</prop> </props> </constructor-arg> </bean>
时: 在字段/参数/方法中使用为:
@Value("#{APP_PROPERTIES.getProperty['testKey']}") String testValue;
3:在配置为:
<bean id="map" class="java.util.HashMap"> <constructor-arg index="0"> <map> <entry key="testKey" value="testValue"/> </map> </constructor-arg> </bean>
时: 在字段/参数/方法中使用为:
@Value("#{map['testKey']}") private String testMapValue;