无法创建请求的服务[org.hibernate.service.jta.platform.spi.JtaPlatform]

问题描述 投票:0回答:2

我正在使用

spring3
hibernate4
和 maven3,我的这段代码给了我这个错误:

Unable to create requested service [org.hibernate.service.jta.platform.spi.JtaPlatform]
 <?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:util="http://www.springframework.org/schema/util"
            xmlns:context="http://www.springframework.org/schema/context"
            xmlns:tx="http://www.springframework.org/schema/tx"
            xmlns:jee="http://www.springframework.org/schema/jee"
            xmlns:mvc="http://www.springframework.org/schema/mvc" 
            xsi:schemaLocation="http://www.springframework.org/schema/beans
                    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                    http://www.springframework.org/schema/mvc 
                    http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
                    http://www.springframework.org/schema/util
                    http://www.springframework.org/schema/util/spring-util-3.0.xsd
                    http://www.springframework.org/schema/tx 
                    http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
                    http://www.springframework.org/schema/context 
                    http://www.springframework.org/schema/context/spring-context.xsd
                    http://www.springframework.org/schema/jee 
                    http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">

            <util:properties id="hibernateProperties" location="classpath:hibernate.properties" />
            <tx:annotation-driven proxy-target-class="true" transaction-manager="transactionManager"/>
            <context:component-scan base-package="com.ecom.data.access.controller" />
            <context:component-scan base-package="com.ecom.data.access.model" />
            <mvc:annotation-driven />
            <bean id="usermanagementSessionFactory"
            class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
            <property name="dataSource" ref="usermanagementDataSource" />
            <property name="configLocation" value="classpath:hibernate.cfg.xml" />
            <!-- <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" /> -->
            <property name="annotatedClasses">
                             <list> 
                                     <value>com.ecom.data.access.model.User</value>
                                     <value>com.ecom.data.access.controller.LoginController</value>
                                     <value>com.ecom.data.access.dao.MyFactory</value>
                             </list>
                     </property>
            <property name="hibernateProperties" ref="hibernateProperties" />
            </bean>

                <jee:jndi-lookup id="usermanagementDataSource" jndi-name="java:jboss/datasources/usermanagementDS" />

                <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
            init-method="init" destroy-method="close">
            <property name="forceShutdown" value="false" />
            <property name ="startupTransactionService" value="false"/>
            </bean>

            <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
            <property name="transactionTimeout" value="30" />
            </bean>

            <bean id="transactionManager"
            class="org.springframework.transaction.jta.JtaTransactionManager">
            <property name="transactionManager" ref="atomikosTransactionManager" />
            <property name="userTransaction" ref="atomikosUserTransaction" />
            </bean>

            <bean id="User" class="com.ecom.data.access.model.User"/>
            <bean id="myFactory" class="com.ecom.data.access.dao.MyFactory"/>
            </beans>

休眠属性文件

hibernate.validator.apply_to_ddl=false
hibernate.validator.autoregister_listeners=false
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=false
hibernate.format_sql=true
#hibernate.query.factory_class=org.hibernate.hql.classic.ClassicQueryTranslatorFactory
hibernate.hbm2ddl.auto=validate
hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider

hibernate.max_fetch_depth=2
hibernate.default_batch_fetch_size=32

hibernate.transaction.manager_lookup_class=com.atomikos.icatch.jta.hibernate4.TransactionManagerLookup
hibernate.transaction.factory_class=org.hibernate.transaction.CMTTransactionFactory

错误:

 Error creating bean with name 'usermanagementSessionFactory' defined in class path resource [applicationContext-dao.xml]: Invocation of init method failed; nested exception is
    hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.service.jta.platform.spi.JtaPlatform]
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486) [spring-beans-3.2.1.RELEASE
    ]
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524) [spring-beans-3.2.1.RELEASE.ja
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) [spring-beans-3.2.1.RELEASE.jar:
           at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) [spring-beans-3.2.1.RELEASE.jar:]
           at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) [spring-beans-3.2.1.RELEASE.jar:]
           at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) [spring-beans-3.2.1.RELEASE.jar:]
           at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) [spring-beans-3.2.1.RELEASE.jar:]
           at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:608) [spring-beans-3.2.1.RELEASE.jar:]
           at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) [spring-context-3.2.1.RELEASE.jar
           at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) [spring-context-3.2.1.RELEASE.jar:]
           at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) [spring-web-3.2.2.RELEASE.jar:]
           at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) [spring-web-3.2.2.RELEASE.jar:]
           at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.2.RELEASE.jar:]
           at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3368) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.core.StandardContext.start(StandardContext.java:3821) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]
           at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824)
           at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759)
           at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_18]
           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_18]
           at java.lang.Thread.run(Thread.java:619) [:1.6.0_18]
    aused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.service.jta.platform.spi.JtaPlatform]
           at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:186) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:150) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:102) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2276) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2272) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1741) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1781) [hibernate-core-4.1.10.Final.jar:]
           at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:247) [spring-orm-3.2.2.RELEASE.jar:]
           at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:373) [spring-orm-3.2.2.RELEASE.jar:]
           at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:358) [spring-orm-3.2.2.RELEASE.jar:]
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545) [spring-beans-3.2.1.RELE
    ar:]
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483) [spring-beans-3.2.1.RELEASE
    ]
           ... 20 more
    aused by: org.hibernate.service.jta.platform.spi.JtaPlatformException: Unable to build org.hibernate.service.jta.platform.internal.TransactionManagerLookupBridge from specifie
    .hibernate.transaction.TransactionManagerLookup implementation: com.atomikos.icatch.jta.hibernate4.TransactionManagerLookup
           at org.hibernate.service.jta.platform.internal.JtaPlatformInitiator.mapLegacyClasses(JtaPlatformInitiator.java:155) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.service.jta.platform.internal.JtaPlatformInitiator.getConfiguredPlatform(JtaPlatformInitiator.java:78) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.service.jta.platform.internal.JtaPlatformInitiator.initiateService(JtaPlatformInitiator.java:60) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.service.jta.platform.internal.JtaPlatformInitiator.initiateService(JtaPlatformInitiator.java:47) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.service.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:69) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:176) [hibernate-core-4.1.10.Final.jar:]
           ... 32 more

    4:57:12,923 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/SpringMVC]] (MSC service thread 1-4) Exception sending context initialized event to list
    instance of class org.springframework.web.context.ContextLoaderListener: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'usermanagement
    onFactory' defined in class path resource [applicationContext-dao.xml]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unabl
    create requested service [org.hibernate.service.jta.platform.spi.JtaPlatform]
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486) [spring-beans-3.2.1.RELEASE
    ]
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524) [spring-beans-3.2.1.RELEASE.ja
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) [spring-beans-3.2.1.RELEASE.jar:
           at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) [spring-beans-3.2.1.RELEASE.jar:]
           at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) [spring-beans-3.2.1.RELEASE.jar:]
           at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) [spring-beans-3.2.1.RELEASE.jar:]
           at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) [spring-beans-3.2.1.RELEASE.jar:]
           at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:608) [spring-beans-3.2.1.RELEASE.jar:]
           at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) [spring-context-3.2.1.RELEASE.jar
           at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) [spring-context-3.2.1.RELEASE.jar:]
           at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) [spring-web-3.2.2.RELEASE.jar:]
           at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) [spring-web-3.2.2.RELEASE.jar:]
           at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.2.RELEASE.jar:]
           at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3368) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.core.StandardContext.start(StandardContext.java:3821) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]
           at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824)
           at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759)
           at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_18]
           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_18]
           at java.lang.Thread.run(Thread.java:619) [:1.6.0_18]
    aused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.service.jta.platform.spi.JtaPlatform]
           at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:186) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:150) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:102) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2276) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2272) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1741) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1781) [hibernate-core-4.1.10.Final.jar:]
           at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:247) [spring-orm-3.2.2.RELEASE.jar:]
           at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:373) [spring-orm-3.2.2.RELEASE.jar:]
           at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:358) [spring-orm-3.2.2.RELEASE.jar:]
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545) [spring-beans-3.2.1.RELE
    ar:]
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483) [spring-beans-3.2.1.RELEASE
    ]
           ... 20 more
    aused by: org.hibernate.service.jta.platform.spi.JtaPlatformException: Unable to build org.hibernate.service.jta.platform.internal.TransactionManagerLookupBridge from specifie
    .hibernate.transaction.TransactionManagerLookup implementation: com.atomikos.icatch.jta.hibernate4.TransactionManagerLookup
           at org.hibernate.service.jta.platform.internal.JtaPlatformInitiator.mapLegacyClasses(JtaPlatformInitiator.java:155) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.service.jta.platform.internal.JtaPlatformInitiator.getConfiguredPlatform(JtaPlatformInitiator.java:78) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.service.jta.platform.internal.JtaPlatformInitiator.initiateService(JtaPlatformInitiator.java:60) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.service.jta.platform.internal.JtaPlatformInitiator.initiateService(JtaPlatformInitiator.java:47) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.service.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:69) [hibernate-core-4.1.10.Final.jar:]
           at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:176) [hibernate-core-4.1.10.Final.jar:]
           ... 32 more

    4:57:13,028 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-4) Error listenerStart
    4:57:13,028 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-4) Context [/SpringMVC] startup failed due to previous errors
    4:57:13,046 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/SpringMVC]] (MSC service thread 1-4) Closing Spring root WebApplicationContext
    4:57:13,050 INFO  [org.jboss.web] (MSC service thread 1-4) registering web context: /SpringMVC
    4:57:13,055 INFO  [org.jboss.as] (MSC service thread 1-1) JBoss AS 7.0.2.Final "Arc" started in 9904ms - Started 184 of 241 services (57 services are passive or on-demand)
    4:57:13,115 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "SpringMVC.war"
spring hibernate jta
2个回答
0
投票

我可以尝试回答您的问题,但您的问题应该包含更多信息:

  1. 您应该包含完整的堆栈跟踪。您在问题中提出的错误中没有足够的信息。完整的堆栈跟踪将添加一些必要的信息来帮助我们弄清楚发生了什么。
  2. 您发布了一个配置文件,但它引用了其他文件,例如
    hibernate.properties
    。您应该包含这些文件,以便我们可以检查您的应用程序的正确配置。

如果没有这些信息,我只能建议以下内容:

  1. 您正在使用 Atomikos 作为交易管理器。您必须包含对 Atomikos 的 Maven 依赖项(您在帖子中说您正在使用 Maven)。
  2. 在声明的bean
    usermanagementSessionFactory
    中,您应该具有与Atomikos相关的属性,如本文档中所述(因为我们看不到hibernate属性,也许您已正确配置它们)。

举个例子,我有一个项目可以与 Spring 3.2.3、Hibernate 4.2.1、Atomikos 3.8.0 和 Ivy 完美配合作为依赖管理器(Ivy 使用与 Maven 相同的信息来声明依赖项,所以你不应该使其适应 Maven 的问题)。我在这里放置了一些配置文件,可以帮助您找到错误:


ivy.xml

<dependency org="org.hibernate" name="hibernate-core" rev="4.2.1.Final"/>
<dependency org="com.atomikos" name="transactions-jdbc" rev="3.8.0" />
<dependency org="com.atomikos" name="transactions-hibernate3" rev="3.8.0" />

spring-config.xml

<bean id="usermanagementSessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSourceA" />
    <property name="annotatedClasses">
        <list>
            <value>com.edt.tests.model.Contact</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.transaction.factory_class">
                org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory 
            </prop> 
            <prop key="hibernate.transaction.manager_lookup_class">
                com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup 
            </prop>
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property>
</bean>

如果您无法使用此信息解决问题,则必须发布有关您所遇到的错误以及您在项目中使用的配置文件的更多信息。


0
投票

我用

hibernate.transaction.jta.platform_resolver
制作的,描述于这里

© www.soinside.com 2019 - 2024. All rights reserved.