SSSP整合配置(Spring版)

resources 创建 applicationContext.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:tx="http://www.springframework.org/schema/tx"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
	   http://www.springframework.org/schema/data/jpa
	   http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
	   http://www.springframework.org/schema/tx
	   http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
	   http://www.springframework.org/schema/context
	   http://www.springframework.org/schema/context/spring-context-4.0.xsd">

        <!-- 配置自动扫描包 -->
        <context:component-scan base-package="priv.linyu.sssp">
            <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
            <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
        </context:component-scan>

        <!-- 配置数据源 -->
        <context:property-placeholder location="classpath:db.properties" />

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${jdbc.driverClass}" />
        <property name="jdbcUrl" value="${jdbc.jdbcUrl}" />
        <property name="user" value="${jdbc.user}" />
        <property name="password" value="${jdbc.password}" />
        <!-- 配置其他属性 -->
    </bean>

    <!-- 配置 JPA 的 EntityManagerFactory -->
    <bean id="entityManagerFactory"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
        </property>
        <property name="packagesToScan" value="priv.linyu.sssp"/>
        <property name="jpaProperties">
            <props>
                <!-- 持久化类和数据库表的列之间的映射策略 -->
                <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
                <!-- 生成数据库表策略 -->
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <!-- 控制台打印SQL语句 -->
                <prop key="hibernate.show_sql">true</prop>
                <!-- 格式化SQL -->
                <prop key="hibernate.format_sql">true</prop>
                <!-- 数据库的方言 -->
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
                <!--  二级缓存信息 -->
                <prop key="hibernate.cache.use_second_level_cache">true</prop>
                <!-- 二级缓存的产品 -->
                <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
                <!-- 查询缓存 -->
                <prop key="hibernate.cache.use_query_cache">true</prop>
            </props>
        </property>
        <property name="sharedCacheMode" value="ENABLE_SELECTIVE"/>
    </bean>

    <!-- 配置 SpringData -->
    <jpa:repositories base-package="priv.linyu.sssp" entity-manager-factory-ref="entityManagerFactory"/>
    <!-- 配置事务 -->
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>

    <!-- 配置支持基于注解的事务 -->
    <tx:annotation-driven transaction-manager="transactionManager"/>

</beans>
posted @ 2021-03-28 00:27  q-linyu  阅读(123)  评论(0)    收藏  举报