码迷,mamicode.com
首页 > 编程语言 > 详细

Spring——集成JPA

时间:2016-10-24 20:35:39      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:cat   ica   spring   service   org   query   asp   oracle   factor   

配置文件如下:<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"
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/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
<context:component-scan base-package="com.xskj.model, com.xskj.repository, com.xskj.service">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>

<!--在原来类的上面加功能-->
<aop:aspectj-autoproxy proxy-target-class="true" />

<!-- 开启事务注解,只对当前配置有效 -->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />

<!--jpa的仓储,你包的位置,前缀,-->
<jpa:repositories base-package="com.xskj.repository" repository-impl-postfix="Impl"
entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="transactionManager" />

<!--数据源-->
<bean name="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"> <!--oracle的驱动-->
<value>oracle.jdbc.driver.MYSQL</value>
<!--
<value>oracle.jdbc.driver.OracleDriver</value>
-->
</property>
<property name="url"><!--客户端地址-->
<!--<value>jdbc:oracle:thin:@localhost:1521:orcl</value>-->
<value>jdbc:oracle:thin:@192.168.8.14:3306:springBoot_data</value>
</property>
<property name="username"> <!--用户名-->
<!-- <value>scott</value>-->
<value>root</value>
</property>
<property name="password"> <!--密码-->
<!--<value>tiger</value>-->
<value>123</value>
</property>
</bean>

<!--事物管理-->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" /> <!--数据源-->
<property name="packagesToScan" value="com.xskj.model" /> <!--model中属性包的位置-->
<property name="persistenceProvider"><!--持久提供者-->
<bean class="org.hibernate.jpa.HibernatePersistenceProvider" />
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <!--设置持久化的框架-->
<property name="generateDdl" value="false" /><!--数据定义语言,创建,删除,修改,truncate清楚表操作等-->
<!--<property name="database" value="ORACLE" />&lt;!&ndash;指定数据库类型用的oracle&ndash;&gt;-->
<property name="database" value="MYSQL" /><!--指定数据库类型用的oracle-->
<!--<property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect" />&lt;!&ndash;数据库的方言&ndash;&gt;-->
<property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" /><!--数据库的方言-->
<property name="showSql" value="true" /><!--执行过程中是否显示sql语句-->
</bean>
</property>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property>
<property name="jpaPropertyMap"><!--jpa属性的一个集合-->
<map>
<entry key="hibernate.query.substitutions" value="true 1, false 0" />
<entry key="hibernate.default_batch_fetch_size" value="16" /><!--hibernate地层批量抓取的-->
<entry key="hibernate.generate_statitics" value="true" /><!--是否让hibernate生产统计信息-->
<entry key="hibernate.bytecode.use_reflection_optimizer" value="true" /><!--字节码的反射机制的优化-->
<entry key="hibernate.cache.use_second_level_cache" value="false" /><!--使用hibernate的二级缓存-->
<entry key="hibernate.cache.use_query_cache" value="false" /><!--hibernate的查询缓存-->
</map>
</property>
</bean>

<!-- 事务管理器配置 -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
</beans>

Spring——集成JPA

标签:cat   ica   spring   service   org   query   asp   oracle   factor   

原文地址:http://www.cnblogs.com/nucdy/p/5994289.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!