Unable to create requested service [org.hibernate.service.jta.platform.spi.JtaPlatform]

倖福魔咒の 提交于 2019-12-25 06:48:07

问题


I am using spring3, hibernate4, and maven3 and my this code gives me this error:

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 properties file

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:

 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"

回答1:


I can try to answer your problem, but your question should include more information:

  1. You should include a full stacktrace. There is not enough information in the error you put in your question. The full stacktrace will add some necessary information to help us figure out what's going on.
  2. You post one configuration file, but it refers to other files, like hibernate.properties. You should include these files so that we can check the correct configuration of your application.

Without this information, I can just suggest the following:

  1. You are using Atomikos as transaction manager. You must include a Maven dependency to Atomikos (you say in your post that you are using Maven).
  2. In the declared bean usermanagementSessionFactory, you should have properties in relation with Atomikos, as it is described in this document (as we can't see the hibernate properties, maybe you have them configured correctly).

As an example, I have a project that works perfectly with Spring 3.2.3, Hibernate 4.2.1, Atomikos 3.8.0 and Ivy as dependency manager (Ivy uses the same information as Maven to declare dependencies, so you shouldn't have problem to adapt it to Maven). I put here some configuration files that can help you find your error:


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>

If you can't solve your problem with this information, you'll have to post more information about the error you have and the configuration files you're using in your project.




回答2:


I made it with hibernate.transaction.jta.platform_resolver, described here.



来源:https://stackoverflow.com/questions/17184540/unable-to-create-requested-service-org-hibernate-service-jta-platform-spi-jtapl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!