日期:2014-05-16  浏览次数:20651 次

spring配置ibatis的jdbc方式和proxool、c3p0连接池方式
spring配置ibatis的jdbc方式和proxool、c3p0连接池方式2010-04-27 14:14spring配置ibatis的jdbc方式和proxool连接池方式,以sqlserver2005为例,驱动为sqljdbc.jar
jdbc.properties中内容如下
jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.url=jdbc\:sqlserver\://localhost\:1433; DatabaseName\=IBATIS
jdbc.username=sa
jdbc.password=1234561 直接用jdbc方式(这种方式适合开发阶段,发布的程序强烈要求用连接池),代码如下,这个都知道,没什么可说的
<?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"
     xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
   
    <context:component-scan base-package="com.mydomain">
        <context:include-filter type="aspectj" expression="com.mydomain.spring..*"/>
    </context:component-scan>
    <context:property-placeholder location="classpath:jdbc.properties" />
    <bean id="dataSource"
         class="org.apache.commons.dbcp.BasicDataSource"
         destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    </bean>

    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
        <property name="configLocation" value="classpath:com/mydomain/data/SqlMapConfig.xml"/>
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <!--事务管理直接用的DataSourceTransactionManager-->
    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <aop:config>
        <aop:pointcut id="baseServiceMethods"
             expression="execution(* com.mydomain.spring.*.*(..))" />
        <aop:advisor advice-ref="txAdvice"
             pointcut-ref="baseServiceMethods" />
    </aop:config>
    <aop:aspectj-autoproxy />
&