【问题标题】:Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration' when run on Docker container在 Docker 容器上运行时创建名为“org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration”的 bean 时出错
【发布时间】:2019-02-03 18:26:18
【问题描述】:

我创建了 spring boot 项目,如果我在本地运行,它运行良好。但是,当我 dockerize 这个应用程序并在 Docker 容器中运行它时。 Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration'出现问题

application.properties

spring.datasource.jdbc-url=xxx
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.maximum-pool-size=100
spring.datasource.testWhileIdle=true
spring.datasource.validationQuery=SELECT 1
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl
spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.default_schema=public
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false

Dockerfile

FROM openjdk:8-jdk
COPY target/app-*.jar /app.jar
EXPOSE 8080/tcp
ENTRYPOINT ["java", "-jar", "/app.jar"]

错误:

2018-08-29 03:56:06.093  WARN 1 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'authorizationServerConfiguration': Unsatisfied dependency expressed through field 'authenticationManager'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webSecurityConfiguration': Unsatisfied dependency expressed through field 'partyPlusUserDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'partyPlusUserDetailsService' defined in URL [jar:file:/app.jar!/BOOT-INF/classes!/com/datnt/pplus/service/user/PartyPlusUserDetailsService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Cannot create inner bean '(inner bean)#71238fc2' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#71238fc2': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'entityManagerFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?
2018-08-29 03:56:06.099  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2018-08-29 03:56:06.140  INFO 1 --- [           main] ConditionEvaluationReportLoggingListener : 

谁能帮我解决这个问题?

【问题讨论】:

  • 您有任何非标准的 Hibernate/数据源配置吗?发布您的配置类。
  • 没有更多与Hibernate/datasource相关的配置
  • 你确定你在类路径中有所有的依赖吗?
  • 我很确定,因为我可以在本地机器上运行,它运行良好。数据库 url 来自远程,而不是 docker,我使用了物理 IP。
  • 如何在本地机器上运行它?如果你在本地通过java -jar app.jar运行它是否有效?

标签: java spring docker spring-boot


【解决方案1】:

检查“application.properties”并将其放在文件夹“src/main/resources”中

【讨论】:

    猜你喜欢
    • 2016-06-22
    • 1970-01-01
    • 2022-07-01
    • 2021-11-28
    • 2020-10-03
    • 2019-08-28
    • 2015-03-18
    • 2021-03-17
    • 2021-06-18
    相关资源
    最近更新 更多