Subversion Repositories SmartDukaan

Rev

Rev 4637 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2010 The myBatis Team Licensed under the Apache License, Version 
    2.0 (the "License"); you may not use this file except in compliance with 
    the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
    Unless required by applicable law or agreed to in writing, software distributed 
    under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES 
    OR CONDITIONS OF ANY KIND, either express or implied. See the License for 
    the specific language governing permissions and limitations under the License. -->

<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:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
     
     
    <!-- this is the service object that we want to make transactional -->
    <bean id="warehouseHandler" class="in.shop2020.warehouse.service.handler.WarehouseServiceHandler"/>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <!-- JDBC connection properties -->
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="#{systemProperties['dbHost']}" />
        <property name="username" value="root" />
        <property name="password" value="shop2020" />

        <!-- Pool size related properties -->
        <!-- The initial number of connections that are created when the pool is 
            started. -->
        <property name="initialSize" value="2" />

        <!-- The maximum number of active connections that can be allocated from 
            this pool at the same time, or negative for no limit. -->
        <property name="maxActive" value="16" />

        <!-- The maximum number of milliseconds that the pool will wait (when there 
            are no available connections) for a connection to be returned before throwing 
            an exception, or -1 to wait indefinitely. -->
        <property name="maxWait" value="10000" />

        <!-- The SQL query that will be used to validate connections from this 
            pool before returning them to the caller. If specified, this query MUST be 
            an SQL SELECT statement that returns at least one row. -->
        <property name="validationQuery" value="SELECT 1" />

        <!-- The indication of whether objects will be validated before being borrowed 
            from the pool. If the object fails to validate, it will be dropped from the 
            pool, and we will attempt to borrow another. -->
        <property name="testOnBorrow" value="false" />

        <!-- The indication of whether objects will be validated by the idle object 
            evictor (if any). If an object fails to validate, it will be dropped from 
            the pool. -->
        <property name="testWhileIdle" value="true" />

        <!-- The minimum amount of time an object may sit idle in the pool before 
            it is eligable for eviction by the idle object evictor. Setting it to 2 hours. -->
        <property name="minEvictableIdleTimeMillis" value="7200000" />

        <!-- The number of milliseconds to sleep between runs of the idle object 
            evictor thread. When non-positive, no idle object evictor thread will be 
            run. Setting it to 15 minutes. -->
        <property name="timeBetweenEvictionRunsMillis" value="1800000"></property>

        <!-- Properties to prevent DB resource leaks -->
        <!-- Flag to remove abandoned connections if they exceed the removeAbandonedTimout. 
            If set to true a connection is considered abandoned and eligible for removal 
            if it has been idle longer than the removeAbandonedTimeout. Setting this 
            to true can recover db connections from poorly written applications which 
            fail to close a connection. -->
        <property name="removeAbandoned" value="true" />

        <!-- Timeout in seconds before an abandoned connection can be removed. -->
        <property name="removeAbandonedTimeout" value="300" />

        <!-- Flag to log stack traces for application code which abandoned a Statement 
            or Connection. Logging of abandoned Statements and Connections adds overhead 
            for every Connection open or new Statement because a stack trace has to be 
            generated -->
        <property name="logAbandoned" value="true" />
    </bean>

    <!-- transaction manager, use JtaTransactionManager for global tx -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <!-- enable component scanning (beware that this does not enable mapper 
        scanning!) -->
    <context:component-scan base-package="in.shop2020.warehouse.handler" />

    <!-- enable autowire -->
    <context:annotation-config />

    <!-- enable transaction demarcation with annotations -->
    <tx:annotation-driven />

    <!-- define the SqlSessionFactory, notice that configLocation is not needed 
        when you use MapperFactoryBean -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation" value="classpath:mybatis-config.xml" />
    </bean>

    <!-- scan for mappers and let them be autowired -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="in.shop2020.warehouse.persistence" />
    </bean>
    
    
</beans>