spring整合mybatis配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">
<!-- 配置组件扫描 -->
<context:component-scan base-package="service,dao,controller,entity,util,aop"></context:component-scan>
<!-- 配置mvc注解扫描 -->
<mvc:annotation-driven></mvc:annotation-driven>

<!-- 开启AOP注解标记 -->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
<!--AOP配置,可用注解

  <aop:config>
  关联REF组件类
  <aop:aspect ref="loggerBean">
  <aop:before method="logController" pointcut="within(controller..*)"/>
  </aop:aspect>

  方法限定类型
  <aop:aspect ref="loggerBean">
  前置通知
  <aop:before method="logController" pointcut="execution(* controller..*(..))"/>
  后置通知
  <aop:after-returning method=""/>
  异常通知
  <aop:after-throwing method=""/>
  最终通知
  <aop:after method=""/>
  @around=环绕通知(前置+后置通知)
  </aop:aspect>
  </aop:config>
-->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dbcp"></property>
</bean>

<tx:annotation-driven transaction-manager="txManager"/>

<util:properties id="config" location="classpath:conf/mysql.properties"></util:properties>
<bean id="dbcp" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  <property name="driverClassName" value="#{config.driverClassName}"></property>
  <property name="url" value="#{config.url}"></property>
  <property name="username" value="#{config.username}"></property>
  <property name="password" value="#{config.password}"></property>
</bean>
<!-- 配置SqlSessionFactoryBean -->
<bean id="ssfb" class="org.mybatis.spring.SqlSessionFactoryBean">
  <property name="dataSource" ref="dbcp"></property>
  <property name="mapperLocations" value="classpath:mapper/*.xml"></property>
</bean>
<!-- MapperScannerConfigurer扫描指定包下的mapper映射器,本质是调用SqlSession的getMapper()
还会降这些对象添加到spring容器,(默认id是首字母小写之后的接口名,也可使用@Respository来设置id) -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  <property name="basePackage" value="dao"></property>
  <!-- <property name="annotationClass" value="dao.annotation.MyBatisRepository"></property> -->
</bean>

</beans>

原文地址:https://www.cnblogs.com/xyz23/p/6343271.html