spring+jpa(hibernate) 配置文件代码

来源:互联网 发布:老司机网络用语 编辑:程序博客网 时间:2024/05/22 11:37
<?xml version="1.0" encoding="UTF-8"?><!-- @version $Id: applicationContext.xml 561608 2007-08-01 00:33:12Z vgritsenko $ --><beans xmlns="http://www.springframework.org/schema/beans"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:util="http://www.springframework.org/schema/util"       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-2.0.xsd                            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd                           http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">        <!--开启注解扫描,不能扫描全部,因为jpa底层原理关系,所以不能使用spring扫描,-->        <context:component-scan base-package="cn.itcast.bos.web.base.action,cn.itcast.bos.service.impl"/>        <!-- 整合 spring data jpa -->         <jpa:repositories base-package="cn.itcast.bos.dao" />        <!--开启事务注解扫描-->        <tx:annotation-driven transaction-manager="transactionManager"/>        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">           <property name="entityManagerFactory" ref="entityManagerFactory"/>        </bean>        <!--连接池-->        <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">            <property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/>            <property name="jdbcUrl" value="jdbc:oracle:thin:@192.168.129.100:1521:orcl"/>            <property name="user" value="xiaoyang"/>            <property name="password" value="xy123"/>        </bean>        <!--spring 跟 jpa整合-->            <!--配置factory-->        <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">            <property name="dataSource" ref="dataSource"/>            <!--包扫描,这个扫描的是 javaBean内容-->            <property name="packagesToScan" value="cn.itcast.domain"/>            <!--持久层使用hibernate框架-->            <property name="persistenceProvider" >                <bean class="org.hibernate.ejb.HibernatePersistence"/>            </property>            <property name="jpaVendorAdapter">                <!-- 自动建表 -->                <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">                    <property name="showSql" value="true"/>                    <property name="generateDdl" value="true"/>                    <property name="database" value="ORACLE"/>                    <!--其实就是数据库方言-->                    <property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect"/>                </bean>            </property>            <property name="jpaDialect">                <!--hql hqpl-->                <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>            </property>        </bean></beans>