Spring3+JPA(hibername4.1)+JTA怎么配置?

发布于 2021-11-13 17:53:51 字数 34 浏览 1006 评论 6

小弟配置了很多次,均不成功!恳请那位大虾帮下忙,谢谢!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

静谧 2021-11-20 11:51:42

我们想使用JTA来实现事务管理

猫烠⑼条掵仅有一顆心 2021-11-20 11:51:38

这是JPA的配置,我需要的Spring+JTA的 服务器是tomcat

为你鎻心 2021-11-20 11:51:36
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
	version="1.0">
	<persistence-unit name="b2b" transaction-type="RESOURCE_LOCAL">
		<properties>
			<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
			<property name="hibernate.connection.driver_class" value="org.gjt.mm.mysql.Driver" />
			<property name="hibernate.connection.username" value="root" />
			<property name="hibernate.connection.password" value="" />
			<property name="hibernate.connection.url" value="jdbc:mysql://10.100.0.33:3306/b2b?useUnicode=true&characterEncoding=UTF-8" />
			<property name="hibernate.max_fetch_depth" value="3" />
			<property name="hibernate.show_sql" value="true" />
			<property name="hibernate.hbm2ddl.auto" value="update" />
			<!-- 二级缓存 -->
			<!-- <property name="hibernate.cache.use_query_cache" value="true"/>
	        <property name="hibernate.cache.use_second_level_cache" value="true"/>
	        <property name="hibernate.cache.use_structured_entries" value="true"/>
	        <property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.EhCacheRegionFactory"/>
	        <property name="net.sf.ehcache.configurationResourceName" value="ehcache.xml"/> -->
        	<!-- C3P0配置 -->
			<property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />
			<property name="c3p0.min_size" value="1" />
			<property name="c3p0.max_size" value="3" />
			<property name="c3p0.maxIdleTime" value="60" />
			<property name="c3p0.timeout" value="1800" />
			<property name="c3p0.max_statements" value="10" />
			<property name="c3p0.idle_test_period" value="120" />
			<property name="c3p0.acquire_increment" value="1" />
			<property name="c3p0.validate" value="true" />
		</properties>
	</persistence-unit>
</persistence>

JPA的META-INF/persistens.xml

浮生未歇 2021-11-20 11:24:08

这是JPA的配置,我需要的Spring+JTA的 服务器是tomcat

醉生梦死 2021-11-20 03:44:31
<?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:mvc="http://www.springframework.org/schema/mvc"
	xmlns:p="http://www.springframework.org/schema/p" 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-3.0.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/mvc   
             http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  
             http://www.springframework.org/schema/context   
             http://www.springframework.org/schema/context/spring-context-3.0.xsd">
   <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="messageConverters">
			<list>
				<bean class="org.springframework.http.converter.StringHttpMessageConverter">
					<property name="supportedMediaTypes">
						<list>
							<value>text/plain;charset=UTF-8</value>
						</list>
					</property>
				</bean>
			</list>
		</property>
	</bean>
	<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
	

	
	
	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="messageConverters">
			<list>
				<bean class="org.springframework.http.converter.StringHttpMessageConverter">
					<property name="supportedMediaTypes">
						<list>
							<value>text/plain;charset=UTF-8</value>
						</list>
					</property>
				</bean>
			</list>
		</property>
	</bean>
	<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
		<property name="prefix" value="/WEB-INF/jsps/" />
		<property name="suffix" value=".jsp" />
	</bean>

	<!-- 另外最好还要加入DefaultAnnotationHandlerMapping,不然会被 XML或其它的映射覆盖! -->
	<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
	<!-- 支持上传文件 -->
	<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
	

</beans>

这个是SPRING MVC的

为你鎻心 2021-11-19 21:49:38
<?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:task="http://www.springframework.org/schema/task" 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-3.0.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/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
           http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
           http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
	<context:annotation-config />  
	<tx:annotation-driven transaction-manager="txManager" />
	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
		<property name="persistenceUnitName" value="b2b" />
	</bean>
	<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
		<property name="entityManagerFactory" ref="entityManagerFactory" />
	</bean>

</beans>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文