SpringMVC---applicationContext.xml配置詳解


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

    <!--使Spring支持自動檢測組件,如注解的@Controller -->
    <context:component-scan base-package="com.parry.test.*" />
    <bean
        class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" />
    <bean
        class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />

    <!-- 數據庫配置 -->
    <bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource"
        destroy-method="close">
        <property name="driverClass" value="com.mysql.jdbc.Driver" />
         <!-- 測試數據庫 -->
        <property name="jdbcUrl"
            value="jdbc:mysql://127.0.0.1:3066/TESTDB?useUnicode=true&amp;characterEncoding=UTF-8&amp;allowMultiQueries=true" />
        <property name="username" value="root" />
        <property name="password" value="root" />
        
        <!-- 檢查數據庫連接池中空閑連接的間隔時間,單位是分,默認值:240,如果要取消則設置為0 -->
        <property name="idleConnectionTestPeriod" value="240" />
        <!-- 連接池中未使用的鏈接最大存活時間,單位是分,默認值:30,如果要永遠存活設置為0 -->
        <!-- 數據庫連接池過期時間應小於等於mysql的過期時間和mycat的過期時間 -->
        <property name="idleMaxAge" value="20" />
        <!-- 每個分區最大的連接數 -->
        <property name="maxConnectionsPerPartition" value="100" />
        <!-- 每個分區最小的連接數 -->
        <property name="minConnectionsPerPartition" value="20" />
        <!-- 分區數 ,默認值2,最小1,推薦3-4,視應用而定 -->
        <property name="partitionCount" value="1" />
        <!-- 每次去拿數據庫連接的時候一次性要拿幾個,默認值:2 -->
        <property name="acquireIncrement" value="2" />
        <!-- 緩存prepared statements的大小,默認值:0 -->
        <property name="statementsCacheSize" value="0" />
        <property name="connectionTimeoutInMs" value="100" />
        <!-- 每個分區釋放鏈接助理進程的數量,默認值:3,除非你的一個數據庫連接的時間內做了很多工作,不然過多的助理進程會影響你的性能 -->
        <property name="releaseHelperThreads" value="3" />
    </bean>
    <!-- 配置SqlSessionFactoryBean -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation" value="classpath:mybatis.xml" />
        <!-- mapper和resultmap配置路徑 -->
        <property name="mapperLocations">
            <list>
                <!-- 表示在com.sfpay.mapper包或以下所有目錄中,以-resultmap.xml結尾所有文件 -->
                <value>classpath:com/parry/test/dao/config/*.xml</value>
            </list>
        </property>
    </bean>
    <!-- 配置mapper接口 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.cn21.calendar.dao" />
    </bean>
    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg index="0" ref="sqlSessionFactory" />
    </bean>
    <!-- 事務配置 -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
    <!-- 用於持有ApplicationContext,可以使用SpringContextHolder.getBean('xxxx')的靜態方法得到spring 
        bean對象 -->
    <bean class="com.parry.test.springcontext.SpringContextHolder"
        lazy-init="false" />

    <!-- 定時器 begin -->
    <!-- 賽程 調度業務對象 -->
    <bean id="deletePastOrderJob" class="com.parry.test.function.PublicTypeFunction" />
    <!-- 賽程 調度業務 -->
    <bean id="deletePastOrderTask"
        class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="deletePastOrderJob" />
        <property name="targetMethod" value="deletePastOrder" />
    </bean>
    <!-- 賽程 調度器觸發器 每天早上07:00執行一次 -->
    <bean id="deletePastOrderTaskTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="deletePastOrderTask" />
        <property name="cronExpression" value="0 13 09 * * ? *" />
    </bean>
    <!-- 設置調度 -->
    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <!-- <ref bean="deletePastOrderTaskTrigger" /> -->
            </list>
        </property>
    </bean>
    <!-- 定時器 end -->
    <!-- 服務器啟動,初始化項目配置參數 -->
    <bean name="InitalizeBean" class="com.parry.test.configure.impl.InitalizeBean" />
</beans>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM