【问题标题】:Error creating bean with name 'entityManagerFactory' spring boot application创建名为“entityManagerFactory”的spring boot应用程序的bean时出错
【发布时间】:2017-07-13 18:31:53
【问题描述】:

当我编译我的 spring boot 项目时,出现以下错误。

org.springframework.beans.factory.BeanCreationException: 错误 创建在类路径中定义的名称为“entityManagerFactory”的bean 资源 [com/biganalytics/project/configuration/JpaConfiguration.class]:Bean 通过工厂方法实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:失败 实例化 [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: 工厂方法“entityManagerFactory”抛出异常;嵌套的 异常是 java.lang.IllegalStateException: required key [datasource.sampleapp.hibernate.dialect] 找不到 org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE] 在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE] 在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE] 在 org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE] 在 com.biganalytics.project.WebApplication.main(WebApplication.java:19) [classes/:na] 由以下原因引起: org.springframework.beans.BeanInstantiationException:失败 实例化 [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: 工厂方法“entityManagerFactory”抛出异常;嵌套的 异常是 java.lang.IllegalStateException: required key [datasource.sampleapp.hibernate.dialect] 找不到 org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 在 org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] ... 18个常用框架 省略原因:java.lang.IllegalStateException: required key [datasource.sampleapp.hibernate.dialect] 找不到 org.springframework.core.env.AbstractPropertyResolver.getRequiredProperty(AbstractPropertyResolver.java:183) ~[spring-core-4.3.6.RELEASE.jar:4.3.6.RELEASE] 在 org.springframework.core.env.AbstractEnvironment.getRequiredProperty(AbstractEnvironment.java:556) ~[spring-core-4.3.6.RELEASE.jar:4.3.6.RELEASE] 在 com.biganalytics.project.configuration.JpaConfiguration.jpaProperties(JpaConfiguration.java:99) 〜[类/:na]在 com.biganalytics.project.configuration.JpaConfiguration.entityManagerFactory(JpaConfiguration.java:81) 〜[类/:na]在 com.biganalytics.project.configuration.JpaConfiguration$$EnhancerBySpringCGLIB$$5f74f23d.CGLIB$entityManagerFactory$1() 〜[类/:na]在 com.biganalytics.project.configuration.JpaConfiguration$$EnhancerBySpringCGLIB$$5f74f23d$$FastClassBySpringCGLIB$$6189aa41.invoke() 〜[类/:na]在 org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.6.RELEASE.jar:4.3.6.RELEASE] 在 org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE] 在 com.biganalytics.project.configuration.JpaConfiguration$$EnhancerBySpringCGLIB$$5f74f23d.entityManagerFactory() ~[classes/:na] 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native 方法)~[na:1.8.0_112] 在 sun.reflect.NativeMethodAccessorImpl.invoke(未知来源) ~[na:1.8.0_112] 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源) ~[na:1.8.0_112] 在 java.lang.reflect.Method.invoke(未知来源) ~[na:1.8.0_112] 在 org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] ... 19个常用框架 省略

请帮忙

【问题讨论】:

  • 转储堆栈跟踪并期待帮助并不是提出问题的好方法。请参阅stackoverflow.com/help/how-to-ask,了解如何提出问题并通过它改进您的问题。 (而且答案基本上在您的堆栈跟踪中,因为它告诉您缺少什么)。
  • 添加您的 application.properties 文件

标签: hibernate jpa spring-boot


【解决方案1】:

Stacktrace 是您的朋友,而不是您的敌人。阅读它们,它们会告诉您您需要知道的一切。在这种特殊情况下,您的特别朋友告诉您错误是

原因:java.lang.IllegalStateException: required key [datasource.sampleapp.hibernate.dialect] not found

因此,将其添加到您的 application.properties 文件中(将 MySQL5Dialect 替换为您正在使用的数据库引擎,以防它不是 MySQL):

datasource.sampleapp.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

我相信你也可以使用

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-20
    • 2021-05-10
    • 2017-05-14
    • 1970-01-01
    • 2017-01-09
    • 1970-01-01
    • 2018-10-27
    相关资源
    最近更新 更多