`
TRAMP_ZZY
  • 浏览: 131934 次
社区版块
存档分类
最新评论

Spring 3.x 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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:security="http://www.springframework.org/schema/security"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
	http://www.springframework.org/schema/security 
    http://www.springframework.org/schema/security/spring-security-3.1.xsd">

	<!-- Root Context: defines shared resources visible to all other web components -->

	<!-- <context:component-scan base-package="edu.bjfu.imovie.daoimpl" /> -->
	<context:component-scan base-package="cn.tramp.iblog.service" />

	<!-- 通过配置的方式在类路径下加载数据库的配置 <context:property-placeholder location="classpath:jdbc.properties"/> -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
		<property name="url"
			value="jdbc:mysql://localhost:3306/iblog?useUnicode=true&amp;characterEncoding=UTF-8" />
		<property name="username" value="root" />
		<property name="password" value="root" />
		<!-- <property name="password" value="Password123" /> -->
	</bean>

	<!-- Spring 提供的JdbcTemplate 方式连接数据库 -->
	<!-- <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> 
		<property name="dataSource"> <ref bean="dataSource"/> </property> </bean> -->

	<!-- 这里的dataSource要与sqlSessionFactory的dataSource一致,否则事务无效 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>

	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="configLocation" value="classpath:mybatis-configuration.xml"></property>
	</bean>
	<!-- 配 置 SqlSessionFactoryBean 来使用基本的 MyBatis 的 ManagedTransactionFactory 
		而不是其 它任意的 Spring 事务管理器 -->
	<!-- <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 
		<property name="dataSource" ref="dataSource" /> <property name="transactionFactory"> 
		<bean class="org.apache.ibatis.transaction.managed.ManagedTransactionFactory" 
		/> </property> </bean> -->

	<!-- 快速加载SQL映射文件 SqlSessionFactoryBean 将直接扫描mapper 类路径下的以xml 为后追的映射文件 -->
	<!-- <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 
		<property name="dataSource" ref="dataSource" /> <property name="configLocation" 
		value="classpath:mybatis-configuration.xml"></property> <property name="mapperLocations" 
		value="classpath:mapper/*.xml"></property> </bean> -->
	<!-- mybatis-spring 提供转换器 MapperScannerConfigurer 可以将映射接口直接转换为Spring 容器中的Bean,这样可以在Service注入映射接口的Bean了。 -->
	<!-- p:sqlSessionFactory-ref="sqlSessionFactory" -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
		p:basePackage="cn.tramp.iblog.dao" p:sqlSessionFactoryBeanName="sqlSessionFactory" />

	<!-- <property name="sqlSessionFactory" ref="sqlSessionFactory"></property> 
		<property name="basePackage" value="edu.bjfu.imovie.dao"></property> </bean> -->

	<!-- 使用SqlSessionTemplate 之后在类中通过注解的方式使用模板,之后使用模板的方法操作数据库 -->
	<!-- <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"> 
		<constructor-arg index="0" ref="sqlSessionFactory" /> </bean> -->

	<!-- SqlSessionTemplate 有一个使用 ExecutorType 作为参数的构造方法。这允许你用来 创建对象,比如,一个批量 SqlSession,但是使用了下列 Spring 
		配置的 XML 文件: -->
	<!--  <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
		<constructor-arg index="0" ref="sqlSessionFactory" />
		<constructor-arg index="1" value="BATCH" />
	</bean>-->

	<!-- 数据映射器类 mapper bean -->
	<!-- <bean id="iUserMapper" class="org.mybatis.spring.mapper.MapperFactoryBean"> 
		<property name="sqlSessionFactory" ref="sqlSessionFactory" /> 注意指定的映射器类必须是一个接口,而不是具体的实现类 
		<property name="mapperInterface" value="edu.bjfu.imovie.dao.IUserMapper" 
		/> </bean> <bean id="iAccountMapper" class="org.mybatis.spring.mapper.MapperFactoryBean"> 
		<property name="sqlSessionFactory" ref="sqlSessionFactory" /> 注意指定的映射器类必须是一个接口,而不是具体的实现类 
		<property name="mapperInterface" value="edu.bjfu.imovie.dao.IAccountMapper" 
		/> </bean> -->
</beans>
分享到:
评论

相关推荐

    spring和Mybatis的xml配置文件提示约束包

    Spring、SpringMVC集成Mybatis所使用到的各版本约束提示包

    spring整合mybatis时需要用到的配置文件

    spring整合mybatis时需要用到的配置文件

    spring+springmvc+mybatis的整合

    这里就要导入mybatis和spring的整合包了,这里sqlsession中也要导入mybatis的配置文件 2.6 spring-bean 配置mapper自动扫描 MapperScannerConfigurer将扫描basePackage所指定的包下的所有接口类(包括子类), ...

    Spring+3.x企业应用开发实战光盘源码(全)

     第12章:讲解了如何在Spring中集成Hibernate、myBatis等数据访问框架,同时,读者还将学习到ORM框架的混用和DAO层设计的知识。  第13章:本章重点对在Spring中如何使用Quartz进行任务调度进行了讲解,同时还涉及...

    Spring.3.x企业应用开发实战(完整版).part2

    2.2.3 类包及Spring配置文件规划 2.3 持久层 2.3.1 建立领域对象 2.3.2 UserDao 2.3.3 LoginLogDao 2.3.4 在Spring中装配DAO 2.4 业务层 2.4.1 UserService 2.4.2 在Spring中装配Service 2.4.3 单元测试 2.5 展现层 ...

    springmybatis

    mybatis实战教程mybatis in action之五与spring3集成附源码 mybatis实战教程mybatis in action之六与Spring MVC 的集成 mybatis实战教程mybatis in action之七实现mybatis分页源码下载 mybatis实战教程mybatis in ...

    Spring3.x企业应用开发实战(完整版) part1

    2.2.3 类包及Spring配置文件规划 2.3 持久层 2.3.1 建立领域对象 2.3.2 UserDao 2.3.3 LoginLogDao 2.3.4 在Spring中装配DAO 2.4 业务层 2.4.1 UserService 2.4.2 在Spring中装配Service 2.4.3 单元测试 2.5 展现层 ...

    Spring集成MyBatis.docx

    六、创建mybatis主配置文件 七、创建Service接口和实现类,属性是dao 八、创建spring的配置文件 九、创建测试类 十、总结 将 MyBatis与 Spring 进行整合,主要解决的问题就是将 SqlSessionFactory 对象交...

    SSM框架教程Spring+SpringMVC+MyBatis全覆盖_Java热门框架视频教程

    3、Spring配置文件详解 4、Spring依赖注入详解 5、Spring相应API 6、Spring数据源集成配置 7、Spring注解开发 8、Spring集成Junit测试 9、Spring集成web环境 10、Spring JDBCTemplate基本使用 11、SpringAOP简介和...

    SSI+Mina2(Struts2+Spring4+Mybatis3+Mina2)集成发布就可运行

    SSI+Mina2(Struts2+Spring4+Mybatis3+Mina2)集成,都是最新的包, 发布就可运行,配置文件都写了详细的注释。

    SpringMVC+Mybatis+Maven 纯XML配置

    3,集成mybatis 4,配置事务 5,另一种配置springMVC的方式 6,自定义(扩展)mvc配置 7,解决@ResponseBody return String的中文乱码问题 8,配置静态资源映射ResourceHandlers 9,配置ViewControllers 10,配置filter 11,...

    SpringMVC+Mybatis JAVA配置 非XML

    3,集成mybatis 4,配置事务 5,另一种配置springMVC的方式 6,自定义(扩展)mvc配置 7,解决@ResponseBody return String的中文乱码问题 8,配置静态资源映射ResourceHandlers 9,配置ViewControllers 10,配置filter 11,...

    Spring Data集成MyBatis完整源码解析

    共计296个文件,主要包括200个Java源码文件,以及39个VM模板、19个XML配置、7个SQL脚本、4个Markdown文档、2个属性文件、2个Shell脚本、2个工厂配置文件和2个Processor文件及2个Mustache模板。该模块特别强化了对...

    spring boot+mybatis整合

    4、在application.yml中添加数据源、Mybatis的实体和配置文件位置。 5、自动生成代码配置文件。 6、建立数据库和表 7、生产Dao层和entity类 8、建立controller层类 9、建立service层类 10、启动之后结果展示 -------...

    Spring+mybatis+SpingMVC+dubbo+zookeeper集成

    通过Spring+mybatis+SpingMVC+dubbo+zookeeper集成,客户端和服务端完成代码。运行代码前请先修改配置数据库配置文件log4j.properties和dubbo配置文件 spring-dubbo.xml。同时需要搭建好自己的zookeeper服务器。

    Struts2+Spring4+MyBatis3 最新包集成发布就可运行

    Struts2+Spring4+MyBatis3 最新包集成发布就可以运行,配置文件都写了很详细的注释。

    陈开雄 Spring+3.x企业应用开发实战光盘源码.zip

    陈开雄 Spring+3.x企业应用开发实战光盘源码 !!!!压缩包的jar包太多,太大无法上传,请谅解,需要的可以联系我 QQ:349721489 第1章:对Spring框架进行宏观性的概述,力图使读者建立起对Spring整体性的认识。 ...

    SpringMVC+Spring+mybatis框架集成(自动生成Mapper)

    SpringMVC+Spring+mybatis框架集成,采用UTF-8编码,直接解压导入myeclipse或eclipse,修改com.xinxinsoft.util下的GeneratorConfig数据库配置信息,再运行com.xinxinsoft.util下的AutoGenerator下的main方法即可...

    基于Spring MVC和Mybatis的Java企业级应用设计源码

    项目共包含293个文件,其中JavaScript源代码文件181个,JPG图片文件31个,Java源代码文件26个,FTL模板文件15个,CSS样式文件14个,XML配置文件7个,PNG图片文件6个,MAP文件4个,项目许可证文件1个,以及Properties...

    SpringMVC+Spring+mybatis框架集成

    SpringMVC+Spring+mybatis框架集成,直接解压导入myeclipse或eclipse,修改com.xinxinsoft.util下的GeneratorConfig数据库配置信息,再运行com.xinxinsoft.util下的AutoGenerator下的main方法即可根据数据库信息自动...

Global site tag (gtag.js) - Google Analytics