You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JHipster Registry中网关未显示,Docker启动失败求助

网关Docker容器启动失败排查与解决

问题描述

为网关应用创建Docker镜像后,执行docker-compose up命令,仅微服务和Registry正常运行,网关未出现在运行实例列表中。

报错日志

22-08-25 10:57:23.661 ERROR 1 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed
mygateway_1                |
mygateway_1                | org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfiguration' defined in file [/app/classes/ma/s2m/nxp/config/SecurityConfiguration.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDetailsService' defined in file [/app/classes/ma/s2m/nxp/security/DomainUserDetailsService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository' defined in ma.s2m.nxp.repository.UserRepository defined in @EnableR2dbcRepositories declared on DatabaseConfiguration: Cannot create inner bean '(inner bean)#139c4f36' of type [org.springframework.data.repository.core.support.RepositoryFragmentsFactoryBean] while setting bean property 'repositoryFragments'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#139c4f36': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepositoryInternalImplFragment': Cannot resolve reference to bean 'userRepositoryInternalImpl' while setting constructor argument; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userRepositoryInternalImpl' defined in file [/app/classes/ma/s2m/nxp/repository/UserRepositoryInternalImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'r2dbcDatabaseClient' defined in class path resource [org/springframework/boot/autoconfigure/r2dbc/ConnectionFactoryDependentConfiguration.class]: Unsatisfied dependency expressed through method 'r2dbcDatabaseClient' parameter 0; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'connectionFactory' defined in class path resource [org/springframework/boot/autoconfigure/r2dbc/ConnectionFactoryConfigurations$PoolConfiguration$PooledConnectionFactoryConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.r2dbc.pool.ConnectionPool]: Factory method 'connectionFactory' threw exception; nested exception is java.lang.IllegalStateException: Unable to create a ConnectionFactory for 'ConnectionFactoryOptions{options={driver=postgresql, database=myGateway, host=mygateway-postgresql, port=5432, user=myGateway}}'. Available drivers: [ h2, pool ]

错误分析

核心问题是应用缺少PostgreSQL的R2DBC驱动依赖,当前环境仅识别到H2和连接池驱动,无法创建PostgreSQL的连接工厂,导致Spring容器初始化失败,网关服务无法启动。

解决方案

  • 添加PostgreSQL R2DBC驱动依赖
    若使用Maven,在pom.xml中引入依赖:

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>r2dbc-postgresql</artifactId>
    </dependency>
    

    若使用Gradle,在build.gradle中添加:

    implementation 'org.postgresql:r2dbc-postgresql'
    
  • 确认依赖被打包到镜像
    重新执行项目构建命令(Maven:mvn clean package;Gradle:./gradlew clean bootJar),确保驱动被包含在最终生成的jar包中。

  • 检查Docker镜像构建逻辑
    查看Dockerfile,确认正确复制了构建后的jar包。例如多阶段构建的Dockerfile需保证依赖层正常复制:

    FROM openjdk:17-jdk-slim as builder
    WORKDIR /app
    COPY . .
    RUN ./mvnw clean package -DskipTests
    
    FROM openjdk:17-jdk-slim
    WORKDIR /app
    COPY --from=builder /app/target/*.jar app.jar
    CMD ["java", "-jar", "app.jar"]
    
  • 验证R2DBC连接配置
    检查应用配置文件(如application.yml)中的R2DBC连接参数是否正确,格式示例:

    spring:
      r2dbc:
        url: r2dbc:postgresql://mygateway-postgresql:5432/myGateway
        username: myGateway
        password: your_database_password
    

内容的提问来源于stack exchange,提问作者Khadija

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 23:54:32