https://blog.csdn.net/fantasic_van/article/details/79011218
一般我们在spring中使用@Value(“${xxx}”)注入某个属性,只需要在sping的配置文件中,加入如下配置:
<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations"><list>
<value>classpath:*.properties</value>
</list>
</property>
</bean>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="properties" ref="configProperties"/>
</bean>
但如果要在Controller中也使用,需要在springmvc的配置文件中,同样加入如上配置,因为controller是属于mvc的
在controller中,即可以使用@Value注解赋值了。
@Value("${leave.processInstanceKey}")
private String leaveProcessInstanceKey;
注意这里不能加static,因为spring注入依赖的是set方法,而set方法,是普通对象的方法,但static是类的属性