不使用 Docker 组合或任何 Docker 容器的 JHipster 微服务集中化,需要帮助

JHipster Microservice Centralization without using Docker compose or any Docker container, need assistance

目前我正在尝试实现的场景

我直接从 git-hub 使用 Jhipster 注册表应用程序,将其用作 Eureka 注册表和 Spring-Cloud-Config 服务器(默认功能虽然)。

我需要在 Jhipster 注册表中集中配置微服务应用程序的配置文件。

所有这些我们都必须在不使用 Docker 的情况下完成,因为当前项目不使用 Docker。 为此,我对 bootstrap.yml 文件如下所示(到 运行 作为复合配置文件,虽然本地文件系统是本地类型,因为我们无权访问生产 git存储库。所以只选择文件系统和 dev /composite 配置文件。 目前我的 boostrap.yml 看起来如下

spring:
  application:
    name: jhipster-registry
  profiles:
    active: dev
    include: composite
  cloud:
    config:
      server:
        
        bootstrap: true
        composite:
          - type: native #git
            
            search-locations: file:/C:/Jhipster_Eureka/jhipster-registry-master/central-config/
            
        prefix: /config
      fail-fast: true
      
      name: jhipster-registry
      profile: composite 

我还在 central-config 文件夹下创建了一个 gateway.yml 文件(网关是我试图集中其配置的微服务示例应用程序之一,是it eureka client, data-source everything which comes by default to application-dev.yml in the Jhipster micro-service gateway app I生成。) 通过说明如下所示的所有配置 gateway.yml

   server:
  port: 8888
management:
  health:
    diskspace:
      enabled: false
# ===================================================================
# JHipster Sample Spring Cloud Config.
# ===================================================================

# Property used on app startup to check the config server status

configserver:
  name: JHipster Registry config server
  status: Connected to the JHipster Registry config server!

# Default JWT secret token (to be changed in production!)
jhipster:
  security:
    authentication:
      jwt:
        # It is recommended to encrypt the secret key in Base64, using the `base64-secret` property.
        # For compabitibily issues with applications generated with older JHipster releases,
        # we use the non Base64-encoded `secret` property here.
        # secret: my-secret-key-which-should-be-changed-in-production-and-be-base64-encoded
        # The `base64-secret` property is recommended if you use JHipster v5.3.0+
        # (you can type `echo 'secret-key'|base64` on your command line)
        base64-secret: bXktc2VjcmV0LWtleS13aGljaC1zaG91bGQtYmUtY2hhbmdlZC1pbi1wcm9kdWN0aW9uLWFuZC1iZS1iYXNlNjQtZW5jb2RlZAo=

spring:
  profiles:
    active: dev
    include:
      - swagger

eureka:
  instance:
    prefer-ip-address: true
  client:
    service-url:
      defaultZone: http://admin:admin@localhost:8761/eureka/



  datasource:
  type: com.zaxxer.hikari.HikariDataSource
  url: jdbc:mysql://localhost:3306/conference?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC&createDatabaseIfNotExist=true
  username: root
  password: root
  hikari:
    poolName: Hikari
    auto-commit: false
    data-source-properties:
      cachePrepStmts: true
      prepStmtCacheSize: 250
      prepStmtCacheSqlLimit: 2048
      useServerPrepStmts: true

  jpa:
    show-sql: true
    liquibase:
      # Remove 'faker' if you do not want the sample data to be loaded automatically
      contexts: dev

问题#1 如果我 运行 我的注册表,它会正常运行,没有任何问题。如果我尝试运行“网关”微服务应用程序而不定义它自己的配置文件(应用程序-dev.yml)中提到的数据源定义,它会在运行时间失败。

运行时间

期间的异常堆栈跟踪
2020-08-06 21:45:58.301  WARN 28804 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]:
 Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthEndpoint' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthContributorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthContributorRegistry]: Factory method 'healthContributorRegistry' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthContributorAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class

我很惊讶它是如何从 gateway.yml 文件而不是数据源中获取 eureka 实例的,所以这里出了什么问题?

问题#2

在gateway.app yml中提到了server.port:8888,但它是spring-cloud-config-server的端口还是微服务应用程序端口,例如8083 . 我观察到,如果我尝试将该端口从 8888 更改为 8083,它会在 运行 时出错,无法找到发现客户端,这是什么问题,或者我是否仍然缺少某些配置?

请让我知道查询现在是否足够详细以便回复。

使用 jhipster-registry 的 JHipster 微服务架构绝对不需要

Docker,您的用例得到了很好的支持,您遇到的问题只是由于您的配置错误。

gateway.yml 未正确缩进,因此 datasource 的 属性 名称不匹配,这就是为什么您会收到有关无法找到 JDBC 驱动程序的错误消息。

spring 块中间的 eureka 块完全破坏了它,无论如何 eureka 配置由所有应用共享,所以它应该放在 application-dev.ymlapplication-prod.yml.

gateway.yml 与环境存储库中的任何其他文件(使用本机时 central-config 文件夹)必须与本地 application.yml 文件的格式完全相同。

如果您对 YAML 文件不满意,可以切换到普通属性。

关于本机存储库中的文件命名,Spring Cloud Config Server doc 说:

If the repository is file-based, the server creates an Environment from application.yml (shared between all clients) and foo.yml (with foo.yml taking precedence). If the YAML files have documents inside them that point to Spring profiles, those are applied with higher precedence (in order of the profiles listed). If there are profile-specific YAML (or properties) files, these are also applied with higher precedence than the defaults.

所以基本上这意味着在您的 central-config 文件夹中您应该有这些文件:

  • application.yml: 未设置配置文件时所有应用程序通用的所有属性
  • application-dev.yml:设置开发配置文件时所有应用程序共有的所有属性。这是您将用于开发的 JWT 秘密,用于开发 Eureka 服务器的 url(通常是本地主机)
  • 的地方
  • application-prod.yml:设置产品配置文件时所有应用程序共有的所有属性。这是你将放置 prod 的 JWT 秘密的地方,url 用于 prod Eureka server
  • gateway.yml: 未设置配置文件时网关应用程序的所有属性
  • gateway-dev.yml:设置开发配置文件时网关应用程序的所有属性。这是放置开发数据源的地方
  • gateway-prod.yml:设置产品配置文件时网关应用程序的所有属性。这是放置产品数据源的地方

因此,当您的网关使用开发配置文件引导时,它将获得 application.yml、application-dev.yml、gateway.yml 和 gateway-dev.yml[=30 的组合=]

只有遵循命名约定{app name}-{profile}.yml

,此机制才能发挥作用

因此,将文件命名为 application-dev-gateway.yml 只是意味着具有 dev-gateway 配置文件的所有应用程序共有的属性,这可能不是您的意思。