Spring配置文件中数据库配置

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <bean id="placeholderConfig"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>classpath:init.properties</value>
        </property>
    </bean>
    <!-- bean id="dataSource"
        class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">
            <value>${datasource.jndiName}</value>
        </property>
    </bean-->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" dependency-check="none">
        <property name="driverClass">
            <value>${datasource.driverClassName}</value>
        </property>
        <property name="jdbcUrl">
           <value>${datasource.url}</value>
        </property>
        <property name="user">
           <value>${datasource.username}</value>
        </property>
        <property name="password">
           <value>${datasource.password}</value>
        </property>
        <property name="acquireIncrement">
           <value>${c3p0.acquireIncrement}</value>
        </property>
        <property name="initialPoolSize">
           <value>${c3p0.initialPoolSize}</value>
        </property>
        <property name="minPoolSize">
           <value>${c3p0.minPoolSize}</value>
        </property>
        <property name="maxPoolSize">
           <value>${c3p0.maxPoolSize}</value>
        </property>
        <property name="maxIdleTime">
           <value>${c3p0.maxIdleTime}</value>
        </property>
        <property name="idleConnectionTestPeriod">
           <value>${c3p0.idleConnectionTestPeriod}</value>
        </property>
        <property name="maxStatements">
           <value>${c3p0.maxStatements}</value>
        </property>
        <property name="numHelperThreads">
           <value>${c3p0.numHelperThreads}</value>
        </property>
  </bean>
    <bean id="Hibernate3SessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref local="dataSource" />
        </property>
        <property name="mappingResources">
            <list>
                <value>com/hwtx/hibernate/hbm/Login.hbm.xml</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    ${hibernate.dialect}
                </prop>
                <prop key="hibernate.show_sql">
                    ${hibernate.show_sql}
                </prop>
                <prop key="hibernate.jdbc.fetch_size">
                    ${hibernate.jdbc.fetch_size}
                </prop>
                <prop key="hibernate.jdbc.batch_size">
                    ${hibernate.jdbc.batch_size}
                </prop>
                <!-- prop key="hibernate.query.factory_class">
                    ${hibernate.query.factory_class}
               </prop-->
            </props>
        </property>
    </bean>
    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
        <ref local="Hibernate3SessionFactory" />
        </property>
    </bean>
<bean id="jdbcExceptionTranslator" class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator">
  <property name="dataSource">
    <ref bean="dataSource" />
  </property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
  <property name="sessionFactory">
    <ref bean="Hibernate3SessionFactory" />
  </property>
  <property name="jdbcExceptionTranslator">
    <ref bean="jdbcExceptionTranslator" />
  </property>
</bean>
<bean id="userDAOProxy"  abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager">
        <ref bean="transactionManager" />
    </property>
    <property name="transactionAttributes">
        <props>
                  <prop key="save*">PROPAGATION_REQUIRED</prop>
                 <prop key="update*">PROPAGATION_REQUIRED</prop>
                  <prop key="find*">PROPAGATION_REQUIRED</prop>
                        <prop key="get*">PROPAGATION_REQUIRED</prop>
                        <prop key="remove*">PROPAGATION_REQUIRED</prop>
                        <prop key="del*">PROPAGATION_REQUIRED</prop>
                        <prop key="*">PROPAGATION_REQUIRED</prop>
        </props>
    </property>
</bean>
<bean id="loginDao" class="com.hwtx.login.LoginDaoImp">
        <property name="sessionFactory">
            <ref local="Hibernate3SessionFactory" />
        </property>
</bean>
<bean id="userDao" class="com.hwtx.user.UserDaoImp">
        <property name="sessionFactory">
            <ref local="Hibernate3SessionFactory" />
        </property>
</bean>
<bean name="/userAction" class="com.hwtx.struts.action.UserAction" >
    <property name="userDao">
        <ref bean="userDao" />
    </property>
</bean>
<bean name="/loginAction" class="com.hwtx.struts.action.LoginAction" >
    <property name="loginDao">
        <ref bean="loginDao" />
    </property>
</bean>
</beans>

init.properties文件

datasource.type=mysql
datasource.driverClassName=com.mysql.jdbc.Driver
datasource.url=jdbc:mysql://localhost:3306/login?useUnicode=true&characterEncoding=UTF-8
datasource.username=root
datasource.password=123

datasource.maxActive=10
datasource.maxIdle=2
datasource.maxWait=120000
datasource.whenExhaustedAction=1
datasource.validationQuery=select 1 from dual
datasource.testOnBorrow=true
datasource.testOnReturn=false

c3p0.acquireIncrement=3
c3p0.initialPoolSize=3
c3p0.idleConnectionTestPeriod=900
c3p0.minPoolSize=2
c3p0.maxPoolSize=50
c3p0.maxStatements=100
c3p0.numHelperThreads=10
c3p0.maxIdleTime=600

hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
#hibernate.dialect=org.hibernate.dialect.MySQLMyISAMDialect
#hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.jdbc.batch_size=25
hibernate.jdbc.fetch_size=50
hibernate.show_sql=true
hibernate.connection.release_mode=after_transaction

#bbscs.isloadconfig=false
#bbscs.safePath=C:/safe/

#cache.config=oscache.properties
#cacheup.config=oscache_up.properties
#cachefl.config=oscache_fl.properties
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值