Spring 配置文件

Spring 配置文件

<?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:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring.xsd">
    <!--<import resource="classpath*:applicationContext-jedis.xml"/>-->

    <!-- 通过bean元素声明需要Spring创建的实例。该实例的类型通过class属性指定,并通过id属性为该实例指定一个名称,以便在程序中使用 -->

    <!--1.读取数据库资源文件database.properties-->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:database.properties"/>
    </bean>
    <!--2.配置数据源 datasource(使用dbcp连接池)-->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" scope="singleton">
        <property name="driverClassName" value="${driver}"/>
        <property name="url" value="${url}"/>
        <property name="username" value="${user}"/>
        <property name="password" value="${password}"/>
        <property name="initialSize" value="${initialSize}"/>
        <property name="maxActive" value="${maxActive}"/>
        <property name="maxIdle" value="${maxIdle}"/>
        <property name="minIdle" value="${minIdle}"/>
        <property name="maxWait" value="${maxWait}"/>
        <property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}"/>
        <property name="removeAbandoned" value="${removeAbandoned}"/>
        <!-- sql心跳    保证连接池中的连接是真是有效的-->
        <!--开启Evict的定时校验,循环校验  -->
        <property name= "testWhileIdle" value="true"/>
        <!-- 在进行borrowObject处理时,会对拿到的 连接进行校验-false-->
        <property name= "testOnBorrow" value="false"/>
        <!-- 在进行ruturnObject处理时,会对返回的连接进行校验-false -->
        <property name= "testOnReturn" value="false"/>
        <!-- 校验使用的sql语句,validatetionQuery,复杂的校验sql会影响性能 -->
        <property name= "validationQuery" value="select 1"/>
        <!-- 定义Evict的时间间隔,单位:毫秒 -->
        <property name= "timeBetweenEvictionRunsMillis" value="60000"/>
        <!-- 配置每次校验连接的数量,一般等于maxActive -->
        <property name= "numTestsPerEvictionRun" value="${maxActive}"/>
    </bean>
    <!--3. 配置session工厂 sqlSessionFactory-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!--关联mybatis配置文件-->
        <!--<property name="configLocation" value="classpath:Mybatis-config.xml"></property>-->
        <property name="dataSource" ref="dataSource"/><!--关联数据源-->
        <!-- 自动扫描mapping.xml文件,**表示迭代查找,也可在sqlMapConfig.xml中单独指定xml文件-->
        <!--<property name="mapperLocations" value="classpath:cn.bdqn.dao/*.xml" />-->
        <property name="mapperLocations" value="classpath:club.ximeng.dao/**/*.xml"/>
        <!--Mybatis设置-->
        <property name="configuration">
            <bean class="org.apache.ibatis.session.Configuration">
                <!-- 下划线匹配驼峰 -->
                <!--<property name="mapUnderscoreToCamelCase" value="true"/>-->
                <!-- 自动匹配模式为全匹配 ResultMap自动映射-->
                <property name="autoMappingBehavior" value="FULL"/>
            </bean>
        </property>
    </bean>
    <!--4. 配置Dao实例(创建dao层对象)  -->   <!--可省略-->
    <!--<bean id="fm" class="org.mybatis.spring.mapper.MapperFactoryBean">-->
    <!--<property name="mapperInterface" value="cn.bdqn.dao.FlowerMapper"/>-->
    <!--<property name="sqlSessionFactory" ref="sqlSessionFactory"/>-->
    <!--</bean>-->
    <!--新4.使用MapperScannerConfigurer 注入映射器 针对Mapper生成实现类对象-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
        <property name="basePackage" value="club.ximeng.dao"/>
    </bean>
    <!--<mybatis-spring:scan base-package="com.jiang.dao"/>-->
    <!--5.配置Service实例(创建servic对象)--><!--可省略-->
    <!--<bean id="fs" class="cn.bdqn.service.impl.FlowerServiceImpl">-->
    <!--<property name="flos" ref="flowerMapper"/>-->
    <!--</bean>-->
    <!--新5.启用注解-->
    <context:component-scan base-package="club.ximeng.service"/>

    <!--加载配置文件属性-->
    <bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:application.properties</value>
            </list>
        </property>
    </bean>

    <!--6. 配置事务 -->
    <!--6.1 配置事务管理器 -->
    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <!--6.2 事务增强    -->
    <tx:advice id="txAdvice" transaction-manager="txManager">
        <tx:attributes>
            <!--propagation 事务传播机制 :-->
            <!--supports(如果存在一个事务,那么就支持当前事务;如果不存在事务,则按非事务方式执行)-->
            <!--REQUIRED(【默认】 如果存在一个事务,那么就支持当前事务;如果不存在事务,新开启一个事务)-->
            <!--REQUIRES_NEW 表示总是开启一个新的事务-->
            <!--NOT_SUPPORTS 表示总是以非事务方式执行-->
            <tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
            <tx:method name="add*" propagation="REQUIRED"/>
            <tx:method name="del*" propagation="REQUIRED"/>
            <tx:method name="update*" propagation="REQUIRED"/>
            <tx:method name="*" propagation="REQUIRED"/>
        </tx:attributes>
    </tx:advice>
    <!-- 6.3 配置切面/织入 -->
    <aop:config>
        <!-- 切入点 -->
        <aop:pointcut expression="execution(* club.ximeng.service..*.*(..))" id="mypoint"/>
        <!-- 织入 -->
        <aop:advisor advice-ref="txAdvice" pointcut-ref="mypoint"/>
    </aop:config>
    <!-- SpringMVC上传文件时,需要配置MultipartResolver处理器 -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="defaultEncoding" value="utf-8"></property>
        <property name="maxUploadSize" value="5242440"></property>
    </bean>
</beans>
#最小空闲数
minIdle=45
#允许最大空闲数  不能配置太小
maxIdle=50
#初始化时 连接个数   默认是0
initialSize=5
#同时连接的最大活动数   默认是8
maxActive=100
#最大等待时间
maxWait=100
#超过这个时间就会将没用的连接回收
removeAbandonedTimeout=180
#是否开启无用连接的回收机制
#【当前空闲连接数<2 && 当前活动数>最大活动数-3】这种情况下会回收
removeAbandoned=true
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值