spring_hibernate.xml配置文件

<?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:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx.xsd
      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
      http://www.springframework.org/schema/aop/spring-aop-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    <bean id="appProperty" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <array>
                <value>classpath:jdbc.properties</value>
            </array>
        </property>
    </bean>
     <!--配置数据源-->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${driver}" />  <!--数据库连接驱动-->
        <property name="jdbcUrl" value="${url}" />     <!--数据库地址-->
        <property name="user" value="${username}" />   <!--用户名-->
        <property name="password" value="${password}" />   <!--密码-->
        <property name="maxPoolSize" value="40" />      <!--最大连接数-->
        <property name="minPoolSize" value="1" />       <!--最小连接数-->
        <property name="initialPoolSize" value="10" />      <!--初始化连接池内的数据库连接-->
        <property name="maxIdleTime" value="20" />  <!--最大空闲时间-->
    </bean>
    <!-- 配置SessionFactory 通过spring提供的LocalSessionFactoryBean进行配置 -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="com.sxkj.entity" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.hbm2ddl.auto">update</prop> <!--hibernate根据实体自动生成数据库表-->
                <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>   <!--指定数据库方言-->
                <prop key="hibernate.show_sql">true</prop>     <!--在控制台显示执行的数据库操作语句-->
                <prop key="hibernate.format_sql">true</prop>     <!--在控制台显示执行的数据哭操作语句(格式)-->
            </props>
        </property>
    </bean>
     <!--配置一个事务管理器-->
    <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    <!--<tx:advice id="txAdvice" transaction-manager="transactionManager">-->
        <!--<tx:attributes>-->
            <!--<tx:method name="Transatoin" isolation="DEFAULT" propagation="REQUIRED" />-->
        <!--</tx:attributes>-->
    <!--</tx:advice>-->
    <!--&lt;!&ndash; 配置AOP &ndash;&gt;-->
    <!--<aop:config>-->
        <!--<aop:pointcut id="pointcut1" expression="execution(* com.sxkj.service.impl.AccountServerImpl.*(..) ))"/>-->
        <!--<aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut1"/>-->
    <!--</aop:config>-->
    <!--<aop:aspectj-autoproxy />-->

    <!--开启事务管理注解-->
    <tx:annotation-driven transaction-manager="transactionManager"/>
</beans>    

猜你喜欢

转载自blog.csdn.net/u010520146/article/details/81198190
今日推荐