1、编写专项配置文件(数据库专项文件)
代码实现:
mysql-url=jdbc:mysql://localhost:3306/test
mysql-driver=com.mysql.jdbc.Driver
2、在xml文件里配置contest
代码实现:
xmlns:context="http://www.springframework.org/schema/context"
3、引入xsd文件
代码实现:
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">
4、将文件配置到xml文件中
代码实现:
<context:property-placeholder location="config/db.properties"/>
5、使用spel表达式将数据接收到bean中
代码实现:
<bean id="UserService" class="springboottest.ioc.UserService" p:userName="${mysql-url}" p:age="20">