Mybatis支持自动扫描、探寻与注入,不需要我们手动去操作,这在节省我们劳动力的同时,也可以大大的节省我们的配置文件。
下面列出比较省时省力简单的配置文件示例:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!--spring扫描的包路径--> <context:component-scan base-package="com.tyyd.*"/> <!-- 启用@Aspect支持 --> <aop:aspectj-autoproxy/> <!-- 等同于下面注掉部分 多个配置文件可用,号分隔 --> <context:property-placeholder location="classpath:init.properties"/> <!-- <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:init.properties</value> </list> </property> </bean> --> <bean name="rDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${readPlatformDriverClassName}"></property> <property name="url" value="${readPlatformUrl}"></property> <property name="username" value="${readPlatformUsername}"/> <property name="password" value="${readPlatformPassword}"></property> <property name="initialSize" value="${readPlatformInitialSize}"></property> <property name="maxActive" value="${readPlatformMaxActive}"></property> <property name="maxIdle" value="${readPlatformMaxIdle}"></property> <property name="maxWait" value="${readPlatformMaxWait}"></property> </bean> <bean id="readSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="rDataSource" /> <!--mybatis的config文件,非mapper映射文件 没有可以不指定--> <!--<property name="configLocation" value="classpath:mybatis/mybatis-config.xml"></property>--> <!--指定mapper映射文件 可以不指定,在下面的MapperScannerConfigurer配置扫描路径即可--> <!--<property name="mapperLocations" value="classpath*:/META-INF/mybatis/**/*.xml" />--> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!--扫描mybatis mapper映射文件的包路径--> <property name="basePackage" value="com.tyyd.dw.mapper" /> <!--这里指定一个注解类,表示扫描下面配置的basePackage路径下注解了该注解类型的class--> <!--如果不指定,则表示扫描全部--> <!--<property name="annotationClass" value="org.springframework.stereotype.Repository" />--> <!--指定SqlSessionFactory,如果只有一个SqlSessionFactory可能不指定,mybatis会自动进行装配--> <!--<property name="sqlSessionFactoryBeanName" value="readSqlSessionFactory"/>--> </bean> <!-- 事务管理器配置,单数据源事务 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="rDataSource" /> </bean> <!-- 配置事务的传播特性 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="del*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="*" read-only="true" /> </tx:attributes> </tx:advice> <!-- 配置哪些方法使用事务 --> <aop:config> <aop:pointcut id="allManagerMethod" expression="execution(* com.tyyd.dw.manager.*.impl.*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod" /> </aop:config> </beans>
相关推荐
springmvc + spring + mybatis + maven整合配置文件
spring和mybatis整合配置文件
spring整合mybatis时需要用到的配置文件
主要用于spring和mybatis的整合,实现SSM架构的应用。
完整的所有配置文件,不会配置的童鞋可以下载了
SpringMVC Spring MyBatis 框架整合需要的jar包 配置文件 工具类
本文档是针对ssm编写的spring与mybatis整合的xml配置文件,后期还会发布mybatis配置文件。
Spring与Mybatis整合,一个简单的demo,包括配置文件等
Spring_Mybatis 整合需要的 jar 包,相关常用的配置文件
ssm框架spring+mybatis+springMvc搭建的框架,MySQL的数据库配置,修改配置文件,将数据库地址改为自己的MySQL地址就可以访问了
此工具自动生成非注解时Spring整合MyBatis时需要的一些配置文件,对于使用较新版本的spring,可以忽视生成的dao的配置文件,建议采用spring的扫描方式。生成的GeneratorConfigXML修改jdbc驱动位置后可直接用使用...
Spring+mybatis+mysql配置文件applictionContext.xml,web.xml,usermapper.xml,dispatcher-servlet.xml
struts2+spring+mybatis整合所需jar包,其中还有配置文件的编写方式!
springmvc spring mybatis 的配置文件模板 .
4、搭建spring和mybatis的配置:spring-mybatis.xm(扫描dao)) 5、测试Spring+mybatis的框架搭建,写单元测试JUnit,测试事务配置等:model-->dao(mapper)-->service-->test 6、映入SpringMVC:配置...
真是不好意思,后来发现Dao层注入是在接口,接口实现类完全没必要要了,但是要保证接口方法和mybatis的配置文件一致,搁着一段时间没弄了,最近又开始捣鼓了,现在加权限到时候在放出来 SSM(struts2+spring3+mybatis)整合...
SSM框架的配置搭建 spring、 spring mvc、 mybatis 整合详解
spring整合springmvc、mybatis的jar包和配置文件,spring整合springmvc、mybatis的jar包和配置文件,spring整合springmvc、mybatis的jar包和配置文件
本文通过实例代码给大家介绍了spring与mybatis整合配置文件的方法,需要的朋友参考下吧
mybatis-spring整合配置文件包mybatis-spring整合配置文件包mybatis-spring整合配置文件包