spring、hibernate整合核心配置文件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: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.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd">


    <!-- 自动扫描注解的bean 多个包以 逗号分隔-->
    <context:component-scan base-package="com.sun" />
    <aop:aspectj-autoproxy proxy-target-class="true"/>
    <!-- 引入jdbc配置文件 -->
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
        <property name="locations">
            <list>
                <value>classpath:properties/*.properties</value>
                <!--要是有多个配置文件,只需在这里继续添加即可 -->
            </list>
        </property>
    </bean>


    <!-- 配置数据源 -->
    <bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <!-- 不使用properties来配置 -->
        <!-- <property name="driverClassName" value="com.mysql.jdbc.Driver" />
            <property name="url" value="jdbc:mysql://localhost:3306/learning" />
            <property name="username" value="root" />
            <property name="password" value="christmas258@" /> -->
        <!-- 使用properties来配置 -->
        <property name="driverClassName" value="${jdbc_driverClassName}" />
        <property name="url" value="${jdbc_url}"/>
        <property name="username" value="${jdbc_username}"/>
        <property name="password" value="${jdbc_password}"/>
    </bean>


    <!-- mapper接口代理实现,自动扫描了所有的XxxxMapper.xml对应的mapper接口文件,这样就不用一个一个手动配置Mpper的映射了,只要Mapper接口类和Mapper映射文件对应起来就可以了。 -->
    <!--<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" >-->
        <!--&lt;!&ndash;指定扫描整个包,多个包用英文","分隔符&ndash;&gt;-->
        <!--<property name="basePackage" value="com.sun.dao" />-->
    <!--</bean>-->


    <!-- 配置Mybatis的文件 ,mapperLocations配置**Mapper.xml文件位置,configLocation配置mybatis-config文件位置-->
   <!-- <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="mapperLocations" value="classpath:orm.mybatis/*.xml"/>
        &lt;!&ndash;<property name="configLocation" value="classpath:config/mybatis-config.xml" />&ndash;&gt;
        &lt;!&ndash; <property name="typeAliasesPackage" value="com.tiantian.ckeditor.model"
            /> &ndash;&gt;
    </bean>-->
    <!--配置hibernate文件,hibernateProperties是-->
    <bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <!--注入连接池-->
        <property name="dataSource" ref="dataSource"/>
        <!--hibernate常用配置-->
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>
        <!--hibernate 映射文件配置-->
        <!--<property name="mappingLocations">
            <list>
                <value>classpath:orm/hibernate/hibernate.hbm.xml</value>
            </list>
        </property>-->
        <!--hibernate 映射包配置-->
        <!--<property name="mappingDirectoryLocations">
            <list>
                <value>classpath:orm/hibernate/</value>
            </list>        </property>-->
        <!--hibernate 自动扫描注解包配置-->
        <!--<property name="packagesToScan">
            <list>
                <value>classpath:com.sun.dto.po</value>
            </list>
        </property>-->
    </bean>


    <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
    <bean id="txManage" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>


    <!--开启事务注解扫描-->
    <tx:annotation-driven transaction-manager="txManage"/>


</beans>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值