applicationContext.xml 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  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" xmlns:tx="http://www.springframework.org/schema/tx"
  5. 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 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  6. <!-- 外部资源导入-->
  7. <context:property-placeholder location="classpath:db.properties"></context:property-placeholder>
  8. <!-- 配置数据库-->
  9. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
  10. <property name="username" value="${jdbc_user}"></property>
  11. <property name="password" value="${jdbc_password}"></property>
  12. <property name="url" value="${jdbc_url}"></property>
  13. </bean>
  14. <!-- 注册dao-->
  15. <bean id="accountDao" class="com.sf.dao.AccountDaoImpl">
  16. <property name="dataSource" ref="dataSource"></property>
  17. </bean>
  18. <!-- 注册service-->
  19. <bean id="accountService" class="com.sf.service.AccountServiceImpl">
  20. <property name="accountDao" ref="accountDao"></property>
  21. </bean>
  22. <!-- 配置事务管理器-->
  23. <bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  24. <property name="dataSource" ref="dataSource"></property>
  25. </bean>
  26. <!-- 开启基于注解的事务管理-->
  27. <tx:annotation-driven transaction-manager="dataSourceTransactionManager"></tx:annotation-driven>
  28. </beans>