Spring+jpa+access
2013-12-02 12:38
585 查看
========访问数据库的属于文件============
driver=com.hxtt.sql.access.AccessDriver
url=jdbc:access:/D:/eclipse/project/jee/workspace/jubweb2/src/message.mdb
dialect=org.hibernate.dialect.SQLServerDialect
path=D:/eclipse/project/jee/workspace/jubweb2/src/message.mdb
uname=
pwd=
==========application.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
">
<context:property-placeholder location="classpath:/META-INF/db.Properties" /><!--连接数据库的属性文件的路径-->
<!-- 把标记了@Controller注解的类转换为bean-->
<context:component-scan base-package="com.jubangit.jubweb2.*" />
<mvc:annotation-driven />
<!--解决web.xml拦截非action路径的问题-->
<mvc:default-servlet-handler/>
<!--spring管理拦截器 -->
<!-- <mvc:interceptors>
<bean class="com.jb.tool.JToolSystemInterceptor" />
</mvc:interceptors> -->
<!-- 定义跳转的文件的前后缀 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- <property name="prefix" value="/WEB-INF/jsp/" /> --> <!-- jsp存放的路径-->
<property name="suffix" value=".jsp" /> <!-- 指定跳转的页面为.jsp格式 -->
</bean>
<!--事物托管-->
<!-- JPA Entity Manager Factory -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" p:dataSource-ref="dataSource">
<property name="packagesToScan" value="com.jubangit.jubweb2.entity"/> <!--如果删除了persistence.xml,则需要指定实体所在的路径否则会报找不到该文件-->
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
<property name="persistenceProvider">
<bean class="org.hibernate.ejb.HibernatePersistence"/><!-- 用于指定持久化实现厂商类 -->
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">${dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.jdbc.fetch_size">18</prop>
<prop key="hibernate.jdbc.batch_size">10</prop>
<!-- <prop key="hibernate.hbm2ddl.auto">create</prop> --><!-- 定义是否自动生成表,create表示每次加载都重新生成,update表示每次加载只是更新表 -->
</props>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"><!--dbcp连接池-->
<property name="driverClassName"><value>${driver}</value></property>
<property name="url"><value>${url}</value></property>
<property name="username"><value>${uname}</value></property>
<property name="password"><value>${pwd}</value></property>
<property name="initialSize"><value>5</value></property>
<property name="maxActive"><value>50</value></property>
<property name="maxIdle"><value>10</value></property>
<property name="minIdle"><value>5</value></property>
<property name="connectionProperties" value="charSet=gbk;"></property><!-- 解决UTF8编码连接读取Access数据库乱码问题 -->
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<!-- 事物通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="sav*" propagation="REQUIRED" rollback-for="Exception"/> <!-- rollback-for回滚事物,果存在一个事务,则支持当前事务。如果没有事务则开启 -->
<tx:method name="del*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="updat*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="qry*" propagation="NOT_SUPPORTED" read-only="true"/>
<tx:method name="*" propagation="NOT_SUPPORTED" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 事物切入 -->
<aop:config>
<aop:pointcut id="cut"
expression="execution(* com.jubangit.jubweb2.services.impl.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="cut" />
</aop:config>
</beans>
driver=com.hxtt.sql.access.AccessDriver
url=jdbc:access:/D:/eclipse/project/jee/workspace/jubweb2/src/message.mdb
dialect=org.hibernate.dialect.SQLServerDialect
path=D:/eclipse/project/jee/workspace/jubweb2/src/message.mdb
uname=
pwd=
==========application.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
">
<context:property-placeholder location="classpath:/META-INF/db.Properties" /><!--连接数据库的属性文件的路径-->
<!-- 把标记了@Controller注解的类转换为bean-->
<context:component-scan base-package="com.jubangit.jubweb2.*" />
<mvc:annotation-driven />
<!--解决web.xml拦截非action路径的问题-->
<mvc:default-servlet-handler/>
<!--spring管理拦截器 -->
<!-- <mvc:interceptors>
<bean class="com.jb.tool.JToolSystemInterceptor" />
</mvc:interceptors> -->
<!-- 定义跳转的文件的前后缀 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- <property name="prefix" value="/WEB-INF/jsp/" /> --> <!-- jsp存放的路径-->
<property name="suffix" value=".jsp" /> <!-- 指定跳转的页面为.jsp格式 -->
</bean>
<!--事物托管-->
<!-- JPA Entity Manager Factory -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" p:dataSource-ref="dataSource">
<property name="packagesToScan" value="com.jubangit.jubweb2.entity"/> <!--如果删除了persistence.xml,则需要指定实体所在的路径否则会报找不到该文件-->
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
<property name="persistenceProvider">
<bean class="org.hibernate.ejb.HibernatePersistence"/><!-- 用于指定持久化实现厂商类 -->
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">${dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.jdbc.fetch_size">18</prop>
<prop key="hibernate.jdbc.batch_size">10</prop>
<!-- <prop key="hibernate.hbm2ddl.auto">create</prop> --><!-- 定义是否自动生成表,create表示每次加载都重新生成,update表示每次加载只是更新表 -->
</props>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"><!--dbcp连接池-->
<property name="driverClassName"><value>${driver}</value></property>
<property name="url"><value>${url}</value></property>
<property name="username"><value>${uname}</value></property>
<property name="password"><value>${pwd}</value></property>
<property name="initialSize"><value>5</value></property>
<property name="maxActive"><value>50</value></property>
<property name="maxIdle"><value>10</value></property>
<property name="minIdle"><value>5</value></property>
<property name="connectionProperties" value="charSet=gbk;"></property><!-- 解决UTF8编码连接读取Access数据库乱码问题 -->
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<!-- 事物通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="sav*" propagation="REQUIRED" rollback-for="Exception"/> <!-- rollback-for回滚事物,果存在一个事务,则支持当前事务。如果没有事务则开启 -->
<tx:method name="del*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="updat*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="qry*" propagation="NOT_SUPPORTED" read-only="true"/>
<tx:method name="*" propagation="NOT_SUPPORTED" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 事物切入 -->
<aop:config>
<aop:pointcut id="cut"
expression="execution(* com.jubangit.jubweb2.services.impl.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="cut" />
</aop:config>
</beans>
相关文章推荐
- 【Java.Spring.DataAccess】ORM Data Access - JPA
- spring data jpa 出现Not a managed type
- 给Java开发者的Play Framework(2.4)介绍 Part2:使用Play,Spring,JPA进行开发
- 深入学习spring-boot系列(二)--使用spring-data-jpa
- JPA+Spring2.5+Struts2.1.8 集成(一)
- 在 Spring Boot 中使用 JPA 和 MySQL
- 动态SQL-Spring Data Jpa
- 手把手教你从最基本的Java工程搭建SpringMVC+SpringDataJPA+Hibernate(含源码下载)
- spring与jpa整合 简化persistence.xml配置文件 使用属性文件 数据源dbcp访问数据库
- spring data Jpa 调用存储过程返回多个out参数
- 继续配置spring data jpa 在tomcat中
- 注解的力量 -----Spring 2.5 JPA hibernate 使用方法的点滴整理(二):进一步消除 hibernate.cfg.xml
- Spring boot通过JPA和Mybatis同时连接2个关系数据库的例子
- Spring:整合JPA
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(一)Spring Boot介绍
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- 使用 Spring Data JPA 简化 JPA 开发
- Spring 4 mvc+shiro+thymeleaf+JPA(Hibernate)+MySql eclipse项目模板
- spring boot 配置及使用 spring data jpa
- spring data jpa使用二级缓存