1. <?xml version="1.0" encoding="UTF-8"?>
    2. <beans xmlns="http://www.springframework.org/schema/beans"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xmlns:context="http://www.springframework.org/schema/context"
    5. xmlns:tx="http://www.springframework.org/schema/tx"
    6. xsi:schemaLocation="http://www.springframework.org/schema/beans
    7. http://www.springframework.org/schema/beans/spring-beans.xsd
    8. http://www.springframework.org/schema/context
    9. https://www.springframework.org/schema/context/spring-context.xsd
    10. http://www.springframework.org/schema/tx
    11. http://www.springframework.org/schema/tx/spring-tx.xsd">
    12. <!-- 组件扫描,扫描 component、service、controller、repository,以及四个自动注入注解-->
    13. <context:component-scan base-package="com.wzy.shiwu"/>
    14. <!-- 数据库连接池 -->
    15. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
    16. <property name="url" value="jdbc:mysql://localhost:3306/myb?useUnicode=true&amp;characterEncoding=utf8"/>
    17. <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    18. <property name="username" value="root"/>
    19. <property name="password" value="941941"/>
    20. </bean>
    21. <!-- JdbcTemplate 对象 -->
    22. <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    23. <property name="dataSource" ref="dataSource"/>
    24. </bean>
    25. <!--创建事务管理器-->
    26. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    27. <!--注入数据源-->
    28. <property name="dataSource" ref="dataSource"></property>
    29. </bean>
    30. <!--开启事务注解-->
    31. <tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>
    32. </beans>