首页 文章

创建名为'entityManagerFactory' spring boot application的bean时出错

提问于
浏览
-2

当我编译我的 Spring 季启动项目时,得到以下错误 .

org.springframework.beans.factory.BeanCreationException:在类路径资源[com / biganalytics / project / configuration / JpaConfiguration.class]中定义的名称为'entityManagerFactory'的bean创建错误:通过工厂方法的Bean实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]:工厂方法'entityManagerFactory'抛出异常;嵌套异常是java.lang.IllegalStateException:在org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)〜[spring-beans-4.3]中找不到所需的密钥[datasource.sampleapp.hibernate.dialect] .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上的org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)~ [spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] . bean.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)〜[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.j ava:483)〜[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306)〜[spring- bean-4.3.6.RELEASE.jar:4.3.6.RELEASE] at 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] at org org.springframework.context.support.AbstractApplicationContext中的.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)~ [spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] . orB.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856)〜[spring]中的getBean(AbstractApplicationContext.java:1081)〜[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE] -CONT在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)〜[spring-context-4.3.6.RELEASE.jar:4.3中的ext-4.3.6.RELEASE.jar:4.3.6.RELEASE] .6.RELEASE] org.springframework上的org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)~ [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE] .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] at 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.RELE ASE] at com.biganalytics.project.WebApplication.main(WebApplication.java:19)[classes /:na]引起:org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] :工厂方法'entityManagerFactory'抛出异常;嵌套异常是java.lang.IllegalStateException:在org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)〜[spring-beans-4.3]中找不到所需的密钥[datasource.sampleapp.hibernate.dialect] .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:在org.springframework.core.env.AbstractPropertyResolver.getRequiredProperty(AbstractPropertyResolver.java:)中找不到所需的键[datasource.sampleapp.hibernate.dialect] 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] at com.biganalytics.project.configuration.JpaConfiguration.jpaProperties(JpaConfiguration.java :99)〜[classes /:na] atcom.biganalytics.project.configuration.JpaConfiguration.entityManagerFactory(JpaConfiguration.java:81)〜[classes /:na] at com.biganalytics.project.configuration.JpaConfiguration $$ EnhancerBySpringCGLIB $$ 5f74f23d.CGLIB $ entityManagerFactory $ 1()〜[ classes /:na] at com.biganalytics.project.configuration.JpaConfiguration $$ EnhancerBySpringCGLIB $$ 5f74f23d $$ FastClassBySpringCGLIB $$ 6189aa41.invoke()〜[classes /:na] at 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] at com.biganalytics.project.configuration.JpaConfiguration $$ EnhancerBySpringCGLIB $$ 5f74f23d.entityManagerFactory()〜[classes /:na] at sun.reflect . NativeMethodAccessorImpl.invoke0(Native Method)〜[na:1.8.0_112] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)〜[na:1 .8.0_112]在org.springframework的java.lang.reflect.Method.invoke(未知来源)〜[na:1.8.0_112]的sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)〜[na:1.8.0_112] .beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)~ [spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] ...省略了19个常用帧

可以帮忙

1 回答

  • 1

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

    引起:java.lang.IllegalStateException:未找到所需的密钥[datasource.sampleapp.hibernate.dialect]

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

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

    我相信你也可以使用

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

相关问题