···
<?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 http://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:jdbc.properties"/>
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="${jdbc.driver}"></property>
<property name="url" value="${jdbc.url}"></property>
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">-->
<property name="dataSource" ref="dataSource"></property>-->
</bean>
<!-- 将dao交给spring管理-->
<bean id="userDao" class="com.gxa.dao.impl.UserDaoImpl">
<property name="jdbcTemplate" ref="jdbcTemplate"></property>
<property name="dataSource" ref="dataSource"></property>
</bean>
</beans>
jdbc配置文件(spring.xml)
于 2024-03-30 14:11:47 首次发布
本文介绍了如何在SpringBoot项目中使用DruidDataSource进行数据库连接管理,并通过JdbcTemplate进行SQL操作,同时展示了如何将DAO组件注入到Spring容器中。
摘要由CSDN通过智能技术生成