ApplicationContext-Dao.xml 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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:aop="http://www.springframework.org/schema/aop"
  5. xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
  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/aop
  9. http://www.springframework.org/schema/aop/spring-aop.xsd
  10. http://www.springframework.org/schema/tx
  11. http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
  12. <!--加载配置文件-->
  13. <context:property-placeholder location="classpath:db.properties"/>
  14. <!--使用bean标签 id必须唯一 class后面加的是具体的实现类(不是接口)的全路径-->
  15. <!--Druid连接池配置-->
  16. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
  17. <property name="driverClassName" value="${jdbc.driver}"/>
  18. <property name="url" value="${jdbc.url}"/>
  19. <property name="username" value="${jdbc.username}"/>
  20. <property name="password" value="${jdbc.password}"/>
  21. </bean>
  22. <!--整合后会话工厂归Spring管理-->
  23. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  24. <!--指定Mybatis核心配置文件-->
  25. <!--<property name="configLocation" value="classpath:SqlMapConfig.xml"/>-->
  26. <!--
  27. <property name="mapperLocations" value="classpath:persagym/em/dao/*.xml"></property>
  28. -->
  29. <property name="mapperLocations">
  30. <list>
  31. <value>classpath*:com/persagy/dao/ReservationMapper.xml</value>
  32. <value>classpath*:com/persagy/dao/RoleMapper.xml</value>
  33. <value>classpath*:com/persagy/dao/RoomMapper.xml</value>
  34. <value>classpath*:com/persagy/dao/UserMapper.xml</value>
  35. </list>
  36. </property>
  37. <!--指定会话工厂使用的数据库连接池-->
  38. <property name="dataSource" ref="dataSource"/>
  39. </bean>
  40. <!--Mapper接口代理(动态代理)方式实现Spring-Mybatis整合-->
  41. <!--使用包扫描的方式批量实现代理
  42. 扫描后可以使用类名首字母小写进行引用-->
  43. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  44. <!--指定需要扫描的包的全路径名称,如果有多个包,用英文输入法状态下的逗号分隔。-->
  45. <property name="basePackage" value="com.persagy.dao"/>
  46. <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
  47. </bean>
  48. </beans>