spring boot error - 引起:java.lang.IllegalStateException:无法配置JTA平台

时间:2016-01-12 15:59:15

标签: java spring hibernate spring-boot

**I am using Java 6/Spring Framework 4.1.4/Spring Boot v1.2.1.RELEASE and Hibernate 3.5. 

由于我在Java6上,我使用嵌入式Tomcat 7.0.59     为什么要尝试JTA(或者我如何抑制ComponentScan)?     这个错误意味着什么以及如何解决它?     我试图使用单独的注释而不是SpringBootApplication并且具有相同的错误。     我正在尝试使用Spring启动来创建服务,然后使用导入资源来加载HB连接等。**

我的application.properties:

server.port=2003
debug=true
spring.datasource.url=jdbc:oracle:thin:@***
spring.datasource.username=***
spring.datasource.password=***
spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
spring.jpa.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect**

我的Gradle片段是:

compile "org.springframework.security:spring-security-web:${springSecurityVersion}"
compile "org.springframework.security:spring-security-config:${springSecurityVersion}"
compile "org.springframework:spring-context:${springVersion}"
compile "org.springframework:spring-web:${springVersion}"
compile "org.springframework:spring-webmvc:${springVersion}"
compile "org.springframework:spring-jms:${springVersion}"
compile "org.springframework:spring-orm:${springVersion}"
compile "org.springframework:spring-jdbc:${springVersion}"
compile "org.springframework.boot:spring-boot-starter-web:${springBootVersion}"
compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}"

代码:

package com.mine.apps.force;
import com.mine.common.ErrorLog;    
@Controller
@EnableAutoConfiguration
@ComponentScan("com.mine")
//@ImportResource("classpath:webserver/forceAppContext.xml")
@RequestMapping(value="/force")
public class forceMicroService
{   
    private static ErrorLog logger = new ErrorLog("forceMicroService");

      public forceMicroService()
      {
      }


      @RequestMapping(value="/retry/{Id}", method=RequestMethod.POST)
      @ResponseBody
      String sendToforce(@PathVariable("Id") String Id)
      {
          String func = "sendToforce";

          logger.Info(func, "Entering");
          return Id;
    }

    public static void main(String[] args)
    {
          SpringApplication.run(forceMicroService.class, args);
    }
}

堆栈跟踪

10:06:11,443 WARN  [embedded.AnnotationConfigEmbeddedWebApplicationContext]: Exception
     在上下文初始化期间遇到

- 取消刷新尝试       org.springframework.beans.factory.BeanCreationException:使用名称' entityManagerFactory'创建bean时出错。在类路径中定义   资源   [组织/ springframework的/引导/自动配置/ ORM / JPA / HibernateJpaAutoConfiguration.class]:   通过工厂方法进行Bean实例化失败;嵌套异常是   org.springframework.beans.BeanInstantiationException:失败   实例   [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]:   工厂方法' entityManagerFactory'抛出异常;嵌套   异常是java.lang.IllegalStateException:无法配置JTA   平台               在org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)               在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111)               在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1006)               在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)               在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)               at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:303)               在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)               在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)               在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)               在org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956)               在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747)               在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)               at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)               在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)               在org.springframework.boot.SpringApplication.run(SpringApplication.java:321)               在org.springframework.boot.SpringApplication.run(SpringApplication.java:961)               在org.springframework.boot.SpringApplication.run(SpringApplication.java:950)               在com.vzw.etm.apps.enforce.EnforceMicroService.main(EnforceMicroService.java:47)       引起:org.springframework.beans.BeanInstantiationException:无法实例化   [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]:   工厂方法' entityManagerFactory'抛出异常;嵌套   异常是java.lang.IllegalStateException:无法配置JTA   平台               在org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)               在org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)               ......还有17个       引起:java.lang.IllegalStateException:无法配置JTA平台               在org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration.getNoJtaPlatformManager(HibernateJpaAutoConfiguration.java:151)               在org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration.configureJtaPlatform(HibernateJpaAutoConfiguration.java:129)               在org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration.customizeVendorProperties(HibernateJpaAutoConfiguration.java:99)               在org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.entityManagerFactory(JpaBaseConfiguration.java:111)               at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration $$ EnhancerBySpringCGLIB $$ 6ecd1b06.CGLIB $ entityManagerFactory $ 6()               at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration $$ EnhancerBySpringCGLIB $$ 6ecd1b06 $$ FastClassBySpringCGLIB $$ 797c76e5.invoke()               在org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)               at org.springframework.context.annotation.ConfigurationClassEnhancer $ BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)               在org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration $$ EnhancerBySpringCGLIB $$ 6ecd1b06.entityManagerFactory()               at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)               at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)               在java.lang.reflect.Method.invoke(Method.java:597)               在org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)               ......还有18个       10:06:11,465 INFO [concurrent.ThreadPoolTask​​Executor]:关闭ExecutorService' metricsExecutor'       2016年1月12日上午10:06:11 org.apache.catalina.core.StandardService stopInternal       信息:停止服务Tomcat

1 个答案:

答案 0 :(得分:4)

Spring Boot不支持Hibernate 3.5 所需的最低版本是Hibernate 4.2。

您可以通过完全禁用Hibernate的自动配置来解决这个问题:

@EnableAutoConfiguration(exclude = {HibernateJpaAutoConfiguration.class})

如果您将服务部署为具有嵌入式Tomcat的可执行JAR,则没有理由使用这样的旧Hibernate版本,因此您应该使用Spring Boot定义的版本。