<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation
="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!--===================================================================-->
    
<!--建立c3p0 dataSource-->
<!--===================================================================-->
    
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<!--===================================================================-->
    
<!--指明数据库驱动(以MySql为例)-->
<!--===================================================================-->
        
<property name="driverClass">
            
<value>com.mysql.jdbc.Driver</value>
        
</property>
<!--===================================================================-->
    
<!--指明数据库地址以及编码-->
<!--===================================================================-->
        
<property name="jdbcUrl">
         
<value>jdbc:mysql://localhost:3306/yxs?useUnicode=true&amp;characterEncoding=UTF-8&amp;autoReconnect=true</value>
        
</property>
<!--===================================================================-->
    
<!--指明数据库的用户名和密码-->
<!--===================================================================-->
        
<property name="properties">
            
<props>
                
<prop key="user">root</prop> 
                
<prop key="password">1234</prop>
<!--===================================================================-->
    
<!--配置c3p0参数-->
<!--===================================================================-->
                
<prop key="hibernate.c3p0.acquire_increment">2</prop>
                
<prop key="hibernate.c3p0.idle_test_period">3000</prop>
                
<prop key="hibernate.c3p0.timeout">5000</prop>
                
<prop key="hibernate.c3p0.max_size">800</prop>
                
<prop key="hibernate.c3p0.min_size">1</prop>
                
<prop key="hibernate.c3p0.max_statements">800</prop>
                
<prop key="hibernate.c3p0.validate">false</prop>
                
<prop key="c3p0.testConnectionOnCheckout">true</prop>
            
</props>
        
</property>
    
</bean>
<!--===================================================================-->
    
<!--把数据源注入给Session工厂-->
<!--===================================================================-->
    
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        
<property name="dataSource" ref="dataSource" />
<!--===================================================================-->
    
<!--配置映射文件-->
<!--===================================================================-->
        
<property name="mappingResources">
            
<list>
                
<value>/com/linying/domain/User.hbm.xml</value>
                
            
</list>
        
</property>
<!--===================================================================-->
    
<!--配置Hibernate-->
<!--===================================================================-->
        
<property name="hibernateProperties">
            
<value>
                hibernate.dialect=com.linying.beans.MySQLDialect
                hibernate.show_sql=true
                hibernate.generate_statistics=true
                hibernate.transaction.flush_before_completion=true
                hibernate.transaction.auto_close_session=true
                hibernate.autoReconnect=true
            
</value>
        
</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="sessionFactory" />
        
</property>
        
<property name="jdbcExceptionTranslator">
            
<ref bean="jdbcExceptionTranslator" />
        
</property>
    
</bean>
    
<bean id="transactionManager"
        class
="org.springframework.orm.hibernate3.HibernateTransactionManager">
        
<property name="sessionFactory" ref="sessionFactory" />
        
<property name="jdbcExceptionTranslator">
            
<ref bean="jdbcExceptionTranslator" />
        
</property>
    
</bean>
    
<bean id="transactionTemplate"
        class
="org.springframework.transaction.support.TransactionTemplate">
        
<property name="transactionManager" ref="transactionManager" />
    
</bean>
<!--DAO================================================================-->
    
<bean id="commonDao" class="com.linying.dao.CommonDaoImpl">
        
<property name="hibernateTemplate" ref="hibernateTemplate"/>
        
<property name="transactionTemplate" ref="transactionTemplate"/>
    
</bean>
<!--beans================================================================-->
    
<bean id="login" class="com.linying.service.login.Login">
        
<property name="commonDao" ref="commonDao"/>
    
</bean>
</beans>
posted on 2010-03-25 20:15 Ying-er 阅读(595) 评论(0)  编辑  收藏 所属分类: SSH

只有注册用户登录后才能发表评论。


网站导航: