zoukankan      html  css  js  c++  java
  • Mybaits整合Spring自动扫描 接口,Mybaits配置文件.xml文件和Dao实体类

    1.转自:https://blog.csdn.net/u013802160/article/details/51815077

     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" xmlns:p="http://www.springframework.org/schema/p"
     4     xmlns:context="http://www.springframework.org/schema/context"
     5     xmlns:mvc="http://www.springframework.org/schema/mvc"
     6     xsi:schemaLocation="http://www.springframework.org/schema/beans    
     7                             http://www.springframework.org/schema/beans/spring-beans-3.1.xsd    
     8                             http://www.springframework.org/schema/context    
     9                             http://www.springframework.org/schema/context/spring-context-3.1.xsd    
    10                             http://www.springframework.org/schema/mvc    
    11                             http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
    12 
    13     <!-- 自动扫描 -->
    14     <context:component-scan base-package="com.goshop" />  
    15 
    16     <!-- 引入配置文件 -->
    17     <bean id="propertyConfigurer"
    18         class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    19         <property name="location" value="classpath:jdbc.properties"></property>
    20     </bean>
    21 
    22     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    23         destroy-method="close">
    24         <property name="driverClassName" value="${driver}" />
    25         <property name="url" value="${url}" />
    26         <property name="username" value="${username}" />
    27         <property name="password" value="${password}" />
    28         <!-- 初始化连接大小 -->
    29         <property name="initialSize" value="${initialSize}"></property>
    30         <!-- 连接池最大数量 -->
    31         <property name="maxActive" value="${maxActive}"></property>
    32         <!-- 连接池最大空闲 -->
    33         <property name="maxIdle" value="${maxIdle}"></property>
    34         <!-- 连接池最小空闲 -->
    35         <property name="minIdle" value="${minIdle}"></property>
    36         <!-- 获取连接最大等待时间 -->
    37         <property name="maxWait" value="${maxWait}"></property>
    38     </bean>
    39 
    40     <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
    41     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    42         <property name="dataSource" ref="dataSource"></property>
    43         <!-- 自动扫描mapping.xml文件 -->
          <!-- 将configLocation去掉,换成mapperLocations则扫描所有xml配置文件 ,-->
          <!-- 如果用configLocation,则可在Configuration.xml 一个一个加载实体配置文件.xml -->
    44 <!-- <property name="configLocation" value="mybatis/SqlMapConfig.xml" /> --> 45 <property name="mapperLocations" value="classpath:com/goshop/mapper/*.xml"></property> 46 </bean> 47 48 <!-- DAO接口所在包名,Spring会自动查找其下的类 --> 49 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 50 <property name="basePackage" value="com.goshop.dao" /> 51 <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> 52 </bean> 53 54 <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx --> 55 <bean id="transactionManager" 56 class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 57 <property name="dataSource" ref="dataSource" /> 58 </bean> 59 60 </beans>

    2.

      <property name="dataSource" ref="dataSource"></property>
    43         <!-- 自动扫描mapping.xml文件 -->
          <!-- 将configLocation去掉,换成mapperLocations则扫描所有xml配置文件 ,-->
          <!-- 如果用configLocation,则可在Configuration.xml 一个一个加载实体配置文件.xml --> 44 <!-- <property name="configLocation" value="mybatis/SqlMapConfig.xml" /> --> <property name="mapperLocations" value="classpath:com/goshop/mapper/*.xml"></property>
  • 相关阅读:
    I.MX6 2014 u-boot 测试修改
    I.MX6 新版、旧版u-boot不兼容问题
    I.MX6 NXP git 仓库
    I.MX6 2G DDR3 16G eMMC
    I.MX6 不一定要设置BOOT_MODE进入烧录模式
    拖动滚动条时某一处相对另一处固定不动(position:fixed)
    layer弹出层
    js设置全局变量ajax中赋值
    spring多个数据源配置
    JS学习之动态加载script和style样式
  • 原文地址:https://www.cnblogs.com/sharpest/p/6139500.html
Copyright © 2011-2022 走看看