Spring注解方式读取配置文件的值
1.在spring.xml中加入
 <!-- 注解使用properties -->
	<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>
2.在类的成员变量上直接加上注解@Value("#{configProperties['xxxxx']}"),这里configProperties即你在xml配置的ref,xxxx即配置文件中的key名称。
                    
                
                
            
        
浙公网安备 33010602011771号