使用spring为类设置成员属性值

一、在spring的配置文件中,使用下面的方法将config.properties文件中的项取值并为类设置成员属性值:

<context:property-placeholder location="classpath:config.properties" />
<bean id="applicationProps" class="com.constants.ApplicationProps">
<property name="profileNoPin" value="${profile.nopin}" />
<property name="profileDefault" value="${profile.default}" />
</bean>


二、Class ApplicationProps.java上不要添加任何注解,不然成员属性是取不到properties文件中的值的。

 

三、通过注解依赖的方式使用ApplicationProps。

其中类的标识“applicationProps” 要与在spring配置文件中的设置的bean id 一致。

 


posted @ 2019-04-18 10:14  翊梦  阅读(561)  评论(0)    收藏  举报