通过xml文件配置开启
<!--数据库相关-->
<?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"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
<property name="password" value="#####"/>
<property name="url" value="########"/>
<property name="username" value="root"/>
<property name="maxActive" value="10"/>
<property name="maxIdle" value="20"/>
</bean>
<!-- 数据库管理器 -->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 增加对事务的支持 -->
<tx:annotation-driven transaction-manager="txManager"/>
<!-- 注解扫描 -->
<context:component-scan base-package="yang.text.entity"/>
<beans/>