spring整合postgre数据源配置

ApplicationContext.xml配置中关于数据源的部分。

使用spring,就不用再操心configuration和sissionFactory等等与业务代码不相关的部分。

<context:component-scan base-package="com.hik" />
    <!--自动扫描的内容-->
     <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"  
        destroy-method="close">  
        <property name="driverClass">  
            <value>org.postgresql.Driver</value>  
        </property>  
        <property name="jdbcUrl">  
            <value>jdbc:postgresql://localhost:5433/test</value>  
        </property>  
        <property name="user">  
            <value>postgres</value>  
        </property>  
        <property name="password">  
            <value>123456</value>  
        </property>  
        <property name="maxPoolSize">  
            <value>80</value>  
        </property>  
        <property name="minPoolSize">  
            <value>1</value>  
        </property>  
        <property name="initialPoolSize">  
            <value>1</value>  
        </property>  
        <property name="maxIdleTime">  
            <value>20</value>  
        </property>  
    </bean>  
    <bean id="sessionFactory"  
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
        <property name="dataSource">  
            <ref local="dataSource" />  
        </property>  
        <property name="mappingResources">  
            <list>  
                <value>com/hik/Entity/Users.hbm.xml</value>  
            </list>  
        </property>  
        <property name="hibernateProperties">  
            <props>  
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>  
                <prop key="show_sql">true</prop>  
                <prop key="hibernate.jdbc.batch_size">20</prop>  
            </props>  
        </property>  
    </bean>  
    <bean id="transactionManager"  
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
        <property name="sessionFactory" ref="sessionFactory" />  
    </bean>  
    <bean id="baseDao" class="com.hik.DaoImpl.UserDaoImpl">  
        <property name="sessionFactory">  
            <ref bean="sessionFactory" />  
        </property>  
    </bean> 

来源:http://blog.5ibc.net/p/87296.html

添加新评论