spring-mybatis整合配置
来源:互联网 发布:500价位耳机知乎 编辑:程序博客网 时间:2024/05/20 00:12
<?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:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<!-- 开启注解模式 -->
<context:annotation-config></context:annotation-config>
<!-- 开启注解扫描 -->
<context:component-scan base-package="com.shop.dao"></context:component-scan>
<!-- 读数据库配置文件 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${driver}" />
<property name="url" value="${url}" />
<property name="username" value="${usernamex}" />
<property name="password" value="${passwordx}" />
<!-- 初始化连接大小
<property name="initialSize" value="20" />-->
<!-- 连接池最大数量
<property name="maxActive" value="100" />-->
<!-- 连接池最大空闲
<property name="maxIdle" value="20" />-->
<!-- 连接池最小空闲
<property name="minIdle" value="20" />-->
<!-- 获取连接最大等待时间
<property name="maxWait" value="20" />-->
</bean>
<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 开启注解驱动 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 配置数据源 -->
<property name="dataSource" ref="dataSource" />
<!-- 各实体类取别名 别名是类的简单名称 -->
<property name="typeAliasesPackage" value="com.shop.bean"></property>
<!-- 自动扫描mapping.xml映射文件,**表示迭代查找 -->
<property name="mapperLocations" value="classpath:com/shop/dao/*.xml" />
</bean>
<!-- DAO接口所在包名,Spring会自动查找其下的类 ,包下的类需要使用@MapperScan注解,否则容器注入会失败 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.shop.dao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
<!-- 配置Spring国际化信息 -->
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="mesages/message"></property>
</bean>
<bean id="CookieLocaleResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="cookieMaxAge" value="604800"></property>
<property name="defaultLocale" value="zh_CN"></property>
<property name="cookieName" value="language"></property>
</bean>
</beans>
<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:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<!-- 开启注解模式 -->
<context:annotation-config></context:annotation-config>
<!-- 开启注解扫描 -->
<context:component-scan base-package="com.shop.dao"></context:component-scan>
<!-- 读数据库配置文件 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${driver}" />
<property name="url" value="${url}" />
<property name="username" value="${usernamex}" />
<property name="password" value="${passwordx}" />
<!-- 初始化连接大小
<property name="initialSize" value="20" />-->
<!-- 连接池最大数量
<property name="maxActive" value="100" />-->
<!-- 连接池最大空闲
<property name="maxIdle" value="20" />-->
<!-- 连接池最小空闲
<property name="minIdle" value="20" />-->
<!-- 获取连接最大等待时间
<property name="maxWait" value="20" />-->
</bean>
<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 开启注解驱动 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 配置数据源 -->
<property name="dataSource" ref="dataSource" />
<!-- 各实体类取别名 别名是类的简单名称 -->
<property name="typeAliasesPackage" value="com.shop.bean"></property>
<!-- 自动扫描mapping.xml映射文件,**表示迭代查找 -->
<property name="mapperLocations" value="classpath:com/shop/dao/*.xml" />
</bean>
<!-- DAO接口所在包名,Spring会自动查找其下的类 ,包下的类需要使用@MapperScan注解,否则容器注入会失败 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.shop.dao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
<!-- 配置Spring国际化信息 -->
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="mesages/message"></property>
</bean>
<bean id="CookieLocaleResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="cookieMaxAge" value="604800"></property>
<property name="defaultLocale" value="zh_CN"></property>
<property name="cookieName" value="language"></property>
</bean>
</beans>
阅读全文
0 0
- mybatis整合spring配置
- Spring 整合mybatis配置
- spring整合mybatis配置
- Spring整合配置Mybatis
- spring-mybatis整合配置
- Spring+Mybatis整合配置xml
- mybatis 与spring整合配置
- 二、Mybatis-Spring整合配置
- SpringMVC+Spring+Mybatis整合配置
- Spring整合mybatis简单配置
- spring 整合 mybatis 详细配置
- 【Spring】XML配置整合Mybatis
- Spring+SpringMVC+Mybatis配置整合
- [spring + springmvc + mybatis] 配置整合
- SpringMVC+Spring+Mybatis整合配置
- Spring+SpringMVC+MyBatis整合配置
- Spring整合MyBatis配置方法
- spring-mybatis整合xml配置
- 并查集(以hdu 1232 畅通工程为例)
- 【数论板子】_我也就会这些
- 原码 补码 反码
- //输入不同对象的姓名、性别、年龄、体重和住址等信息,并输出显示。
- 编程内功心法:如何写代码?
- spring-mybatis整合配置
- CrawlSpiders
- 20位顶级大咖带你践行大数据(内附演讲视频和PPT)
- sql 输出连续日期、月份、年份
- NumPy教程之(二)
- java 判断文件,判断文件夹是否存在.
- 2016 ACM/ICPC Asia Regional Qingdao Online
- 1.创建一个Rectangle类,添加width和height两个成员变量。 2.在Rectangle中添加两种方法分别计算矩形的周长和面积 3.编程利用Rectangle输出一个矩形的周
- C# winform textbox 水印效果