Spring integrates mybatis configuration xml

configuration information

<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:cache="http://www.springframework.org/schema/cache" xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
        http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.1.xsd">

    <description>Spring公共配置</description>

    <!-- 使用annotation 自动注册bean,并检查@Required,@Autowired的属性已被注入 -->
    <context:component-scan base-package="com.*">
<!--        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> -->
    </context:component-scan>
    <aop:aspectj-autoproxy proxy-target-class="true" />

    <context:property-placeholder ignore-resource-not-found="true" ignore-unresolvable="true" location="classpath:properties/datasource.properties" />

    <bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
        <property name="driverClass" value="${jdbc.driver}" />
        <property name="jdbcUrl" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <property name="idleConnectionTestPeriodInMinutes" value="${idleConnectionTestPeriodInMinutes}" />
        <property name="idleMaxAgeInMinutes" value="${idleMaxAgeInMinutes}" />
        <property name="maxConnectionAgeInSeconds" value="${maxConnectionAgeInSeconds}" />
        <property name="maxConnectionsPerPartition" value="${maxConnectionsPerPartition}" />
        <property name="minConnectionsPerPartition" value="${minConnectionsPerPartition}" />
        <property name="partitionCount" value="${partitionCount}" />
        <property name="acquireIncrement" value="${acquireIncrement}" />
        <property name="statementsCacheSize" value="${statementsCacheSize}" />
        <property name="releaseHelperThreads" value="${releaseHelperThreads}" />
        <property name="defaultAutoCommit" value="false" />
    </bean>

    <!-- MyBatis配置 -->
    <bean id="sessionFactory" name="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->
        <property name="typeAliasesPackage" value="com.cnbn.apollo" />
        <!-- 显式指定Mapper文件位置 -->
        <property name="mapperLocations" value="classpath*:com/cnbn/apollo/**/mapper/*Mapper.xml" />
    </bean>

    <!-- 扫描basePackage下所有以@MyBatisRepository标识的 接口 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.**" />
        <property name="annotationClass" value="com.**.mybatis.Repository" />
        <property name="sqlSessionFactoryBeanName" value="sessionFactory" />
    </bean>

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />

    <!-- Redis连接池配置. -->
    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <!-- 连接池中最大连接数。高版本:maxTotal,低版本:maxActive -->
        <property name="maxTotal" value="${redis.maxTotal}" />
        <!-- 连接池中最大空闲的连接数. -->
        <property name="maxIdle" value="${redis.maxIdle}" />
        <!-- 连接池中最少空闲的连接数. -->
        <property name="minIdle" value="${redis.minIdle}" />
        <!-- 当连接池资源耗尽时,调用者最大阻塞的时间,超时将跑出异常。单位,毫秒数;默认为-1.表示永不超时。高版本:maxWaitMillis,低版本:maxWait -->
        <property name="maxWaitMillis" value="${redis.maxWaitMillis}" />
        <!-- 连接空闲的最小时间,达到此值后空闲连接将可能会被移除。负值(-1)表示不移除. -->
        <property name="minEvictableIdleTimeMillis" value="${redis.minEvictableIdleTimeMillis}" />
        <!-- 对于“空闲链接”检测线程而言,每次检测的链接资源的个数。默认为3 -->
        <property name="numTestsPerEvictionRun" value="${redis.numTestsPerEvictionRun}" />
        <!-- “空闲链接”检测线程,检测的周期,毫秒数。如果为负值,表示不运行“检测线程”。默认为-1. -->
        <property name="timeBetweenEvictionRunsMillis" value="${redis.timeBetweenEvictionRunsMillis}" />
        <!-- testOnBorrow:向调用者输出“链接”资源时,是否检测是有有效,如果无效则从连接池中移除,并尝试获取继续获取。默认为false。建议保持默认值. -->
        <!-- testOnReturn:向连接池“归还”链接时,是否检测“链接”对象的有效性。默认为false。建议保持默认值. -->
        <!-- testWhileIdle:向调用者输出“链接”对象时,是否检测它的空闲超时;默认为false。如果“链接”空闲超时,将会被移除。建议保持默认值. -->
        <!-- whenExhaustedAction:当“连接池”中active数量达到阀值时,即“链接”资源耗尽时,连接池需要采取的手段, 默认为1(0:抛出异常。1:阻塞,直到有可用链接资源。2:强制创建新的链接资源) -->
    </bean>

    <bean id="jedisPool" class="redis.clients.jedis.JedisPool">
        <constructor-arg name="poolConfig" ref="jedisPoolConfig" />
        <constructor-arg name="host" value="${redis.host}" />
        <constructor-arg name="port" value="${redis.port}" />
        <constructor-arg name="timeout" value="${redis.timeout}" />
        <constructor-arg name="password" value="${redis.password}"/>
    </bean>

    <bean id="simpleRedisHashCache" class="com.cnbn.apollo.cache.service.SimpleRedisHashCache">
        <property name="jedisPool" ref="jedisPool"></property>
    </bean>

</beans>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325860154&siteId=291194637