Spring配置相关

1.Spring中通过@Value注解注入属性的方式
<!-- 方式一、PropertyPlaceholderConfigurer,访问方式@Value("${tag}") -->
<bean id="appProperty"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:app.properties"/>
</bean>
<!-- 方式二、PreferencesPlaceholderConfigurer,访问方式@Value("${tag}") -->
<bean id="appProperty2"
class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="location" value="classpath:app2.properties" />
</bean>
<!-- 方式三、PropertiesFactoryBean,访问方式@Value("#{appProperty3['tag']}") -->
<bean id="appProperty3" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location" value="classpath:app3.properties" />
</bean>
<!-- 方式四、util:properties,同PropertiesFactoryBean,访问方式@Value("#{appProperty4['tag']}") -->
<util:properties id="appProperty4" location="classpath:app4.properties"></util:properties>

猜你喜欢

转载自www.cnblogs.com/freelymen/p/8794568.html