spring.xml 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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:component-scan base-package="com.cdxw.ssm">
  8. <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  9. </context:component-scan>
  10. <!--引入jdbc.properties-->
  11. <context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
  12. <!--配置数据源-->
  13. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
  14. <property name="driverClassName" value="${jdbc.driver}"></property>
  15. <property name="url" value="${jdbc.url}"></property>
  16. <property name="username" value="${jdbc.username}"></property>
  17. <property name="password" value="${jdbc.password}"></property>
  18. </bean>
  19. <!--配置事务管理器-->
  20. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  21. <property name="dataSource" ref="dataSource"></property>
  22. </bean>
  23. <!--
  24. 开启事务的注解驱动
  25. 将使用@Transactional标识的方法或类中所有的方法进行事务管理
  26. -->
  27. <tx:annotation-driven transaction-manager="transactionManager"/>
  28. <!--配置SqlSessionFactoryBean,可以直接在Spring的IOC中获取SqlSessionFactory-->
  29. <bean class="org.mybatis.spring.SqlSessionFactoryBean">
  30. <!--设置MyBatis的核心配置文件的路径-->
  31. <property name="configLocation" value="classpath:mybatis-config.xml"></property>
  32. <!--设置数据源-->
  33. <property name="dataSource" ref="dataSource"></property>
  34. <!--设置类型别名所对应的包-->
  35. <property name="typeAliasesPackage" value="com.cdxw.ssm.pojo"></property>
  36. <!--
  37. 设置映射文件的路径,在设置了MapperScannerConfigurer的情况下
  38. 只有映射文件的包和mapper接口的包不一致时需要设置;
  39. 如果没有设置MapperScannerConfigurer,则一定要设置
  40. -->
  41. <!-- <property name="mapperLocations" value="classpath:mappers/*.xml"></property>-->
  42. <!--配置分页插件,可以在mybatis的配置文件中配置-->
  43. <!-- <property name="plugins">-->
  44. <!-- <array>-->
  45. <!-- <bean class="com.github.pagehelper.PageInterceptor"></bean>-->
  46. <!-- </array>-->
  47. <!-- </property>-->
  48. </bean>
  49. <!--
  50. 配置mapper接口的扫描,可以将指定包下所有的mapper接口,通过
  51. SqlSession创建代理实现类对象,并将这些对象交给IOC容器管理
  52. -->
  53. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  54. <property name="basePackage" value="com.cdxw.ssm.mapper"></property>
  55. </bean>
  56. </beans>