<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd" > <context:component-scan base-package="com.letv.mytest"></context:component-scan> <context:property-placeholder location="classpath:spring-test.properties" ignore-resource-not-found="true" file-encoding="UTF-8" /> <!-- 这个配置和上面context:property-placeholder 配置一样,可以在配置文件中读出properties配置中的值 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <value>classpath:spring-test.properties</value> </property> <property name="systemPropertiesMode"> <value>1</value> </property> <property name="searchSystemEnvironment"> <value>true</value> </property> <property name="ignoreUnresolvablePlaceholders"> <value>true</value> </property> </bean> --> <!-- 这个配置可以直接给bean赋值 @Value("#{appProperties['ad.name']}") --> <bean id="appProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="ignoreResourceNotFound" value="true" /> <property name="fileEncoding" value="UTF-8" /> <property name="locations"> <list> <value>classpath:spring-test.properties</value> </list> </property> </bean> <bean id="myBean" class=" com.letv.mytest.model.User"> <property name="name"><value>${name}</value></property> <property name="age"><value>${age}</value></property> </bean> </beans>