美文网首页
maven项目SSH整合Spring的配置文件

maven项目SSH整合Spring的配置文件

作者: itcode | 来源:发表于2017-11-29 16:45 被阅读25次
<?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:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!--开启自动扫描-->
    <context:component-scan base-package="com.kaishengit"/>

    <!--数据库连接池-->
    <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql:///mybatis?useSSL=false"/>
        <property name="username" value="root"/>
        <property name="password" value="123456"/>
    </bean>

    <!--Hibernate的SessionFactory-->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <!--数据库连接池-->
        <property name="dataSource" ref="dataSource"/>
        <!--hiberbate的相关配置-->
        <property name="hibernateProperties">
            <props>
                <!--dialect 方言-->
                <prop key="dialect">org.hibernate.dialect.MySQLDialect</prop>
                <!--显示Hibernate自动生成的SQL-->
                <prop key="show_sql">true</prop>
            </props>
        </property>
        <!--POJO类的注册-->
        <property name="packagesToScan" value="com.kaishengit.pojo"/>
    </bean>

    <!--事务管理器-->
    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    <tx:annotation-driven transaction-manager="transactionManager"/>


</beans>

附加:没有整合Spring时的Hibernate主配置文件

hiberate。

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <!--数据库连接-->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql:///mybatis?useSSL=false</property>
        <property name="connection.username">root</property>
        <property name="connection.password">123456</property>

        <!--dialect 方言-->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

        <!--数据库连接池 C3P0 添加C3P0依赖-->
        <property name="c3p0.max_size">2</property>
        <property name="c3p0.min_size">2</property>
        <property name="c3p0.timeout">5000</property>
        <property name="c3p0.max_statements">100</property>
        <property name="c3p0.idle_test_period">3000</property>
        <property name="c3p0.acquire_increment">2</property>
        <property name="c3p0.validate">false</property>

        <!--显示Hibernate自动生成的SQL-->
        <property name="show_sql">true</property>

        <property name="current_session_context_class">thread</property>

        <!--开启二级缓存 设置二级缓存的实现类-->
        <property name="hibernate.cache.region.factory_class">
            org.hibernate.cache.ehcache.EhCacheRegionFactory
        </property>
        <!--设置事务的隔离级别-->
        <!--<property name="connection.isolation">4</property>-->

        <!--映射文件的注册-->
        <mapping resource="hbm/User.hbm.xml"/>
        <mapping resource="hbm/Address.hbm.xml"/>
        <mapping resource="hbm/Teacher.hbm.xml"/>
        <mapping resource="hbm/Student.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

相关文章

网友评论

      本文标题:maven项目SSH整合Spring的配置文件

      本文链接:https://www.haomeiwen.com/subject/jgcpbxtx.html