jdbc.xml 1.7 KB

1234567891011121314151617181920212223242526272829303132333435
  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="
  7. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
  8. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
  9. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
  10. <context:component-scan base-package="com.lovecoding" />
  11. <context:property-placeholder location="mysql.properties" />
  12. <!-- 配置数据库事务对象 -->
  13. <bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
  14. <property name="dataSource" ref="dataSource" />
  15. </bean>
  16. <!-- 启动注解配置数据库事务 -->
  17. <tx:annotation-driven transaction-manager="dataSourceTransactionManager" />
  18. <!-- 数据源 -->
  19. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
  20. <property name="username" value="${mysql.username}" ></property>
  21. <property name="driverClassName" value="${mysql.driver}" ></property>
  22. <property name="password" value="${mysql.passwd}" ></property>
  23. <property name="url" value="${mysql.url}" ></property>
  24. </bean>
  25. <!-- 配置 Spring jdbc 对象 -->
  26. <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >
  27. <property name="dataSource" ref="dataSource" />
  28. </bean>
  29. </beans>