1、首先开启空间: xmlns:context=”http://www.springframework.org/schema/context”
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
2、使用context:property-placeholder标签,location:指定文件路径
3、使用${属性名}获取配置文件数据
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="classpath:data.properties" />
<bean id="userDao" class="com.example.dao.Impl.UserDaoImpl">
<property name="userName" value="${username}" />
<property name="password" value="${pwd}" />
</bean>
<bean id="bookDao" class="com.example.dao.Impl.BookDaoImpl" />
<bean id="userService" class="com.example.service.Impl.UserServiceImpl">
<property name="userDao" ref="userDao" />
<property name="bookDao" ref="bookDao" />
</bean>
</beans>