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 http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
    6. <!--扫描service包-->
    7. <context:component-scan base-package="ssm.shiro.service.impl"></context:component-scan>
    8. <!--创建dbcp数据源连接池-->
    9. <context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
    10. <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    11. <property name="driverClassName" value="${driver}"></property>
    12. <property name="url" value="${url}"></property>
    13. <property name="username" value="${user}"></property>
    14. <property name="password" value="${password}"></property>
    15. </bean>
    16. <!--创建mybatis的SqlSessionFactory工厂类对象-->
    17. <bean class="org.mybatis.spring.SqlSessionFactoryBean">
    18. <property name="dataSource" ref="dataSource"></property>
    19. <!---->
    20. <!--<property name="configLocation" value="classpath:mybatis.xml"></property>-->
    21. <!--指定mapper文件的地址 此处可以使用*号同配置,表示加载包下所有的xml结尾的mapper文件-->
    22. <property name="mapperLocations" value="classpath:/mapper/*.xml"></property>
    23. </bean>
    24. <!--配置扫描mybatis的dao接口 ,会为dao接口创建myabtis的dao接口实现类对象,放置到session工厂中-->
    25. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    26. <property name="basePackage" value="ssm.shiro.dao"></property>
    27. </bean>
    28. <!--声明spring 的事物管理器对象-->
    29. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    30. <property name="dataSource" ref="dataSource"></property>
    31. </bean>
    32. <!--声明以注解的方式配置spring 的事物-->
    33. <tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>
    34. <!--引入spring 和shiro集成的主配置文件-->
    35. <import resource="classpath:spring-shiro.xml"></import>
    36. </beans>