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:aop="http://www.springframework.org/schema/aop"
    6. xmlns:tx="http://www.springframework.org/schema/tx"
    7. xsi:schemaLocation="http://www.springframework.org/schema/beans
    8. http://www.springframework.org/schema/beans/spring-beans.xsd
    9. http://www.springframework.org/schema/context
    10. http://www.springframework.org/schema/context/spring-context.xsd
    11. http://www.springframework.org/schema/aop
    12. http://www.springframework.org/schema/aop/spring-aop.xsd
    13. http://www.springframework.org/schema/tx
    14. http://www.springframework.org/schema/tx/spring-tx.xsd">
    15. <!-- 开启注解扫描,管理service和dao -->
    16. <context:component-scan base-package="com.itheima.ssm.service">
    17. </context:component-scan>
    18. <context:component-scan base-package="com.itheima.ssm.dao">
    19. </context:component-scan>
    20. <context:property-placeholder location="classpath:db.properties"/>
    21. <!-- 配置连接池 -->
    22. <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    23. <property name="driverClass" value="${jdbc.driver}"/>
    24. <property name="jdbcUrl" value="${jdbc.url}"/>
    25. <property name="user" value="${jdbc.username}"/>
    26. <property name="password" value="${jdbc.password}"/>
    27. </bean>
    28. <!-- mybatis plus的配置 -->
    29. <bean id="globalConfiguration" class="com.baomidou.mybatisplus.entity.GlobalConfiguration">
    30. <property name="dbColumnUnderline" value="true"/>
    31. <property name="idType" value="0"/>
    32. <!--<property name="tablePrefix" value="tbl_"/>-->
    33. </bean>
    34. <!-- 把交给IOC管理 SqlSessionFactory -->
    35. <!-- 下面两个分别是mybatis与mybatis-plus -->
    36. <!--org.mybatis.spring.SqlSessionFactoryBean-->
    37. <bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean">
    38. <property name="dataSource" ref="dataSource"/>
    39. <property name="configLocation" value="classpath:mybatis.xml"/>
    40. <!-- 配置pageHelper -->
    41. <property name="plugins">
    42. <array>
    43. <bean class="com.github.pagehelper.PageInterceptor">
    44. <property name="properties">
    45. <props>
    46. <prop key="helperDialect">mysql</prop>
    47. <prop key="reasonable">true</prop>
    48. </props>
    49. </property>
    50. </bean>
    51. </array>
    52. </property>
    53. <property name="globalConfig" ref="globalConfiguration"/>
    54. </bean>
    55. <!-- 扫描dao接口 和mapper文件-->
    56. <bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    57. <property name="basePackage" value="com.itheima.ssm.dao"/>
    58. </bean>
    59. <!-- 配置Spring的声明式事务管理 -->
    60. <!-- 配置事务管理器 -->
    61. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    62. <property name="dataSource" ref="dataSource"/>
    63. </bean>
    64. <tx:annotation-driven transaction-manager="transactionManager"/>
    65. </beans>