[英]JHipster Microservice Centralization without using Docker compose or any Docker container, need assistance
目前的情況是我正在嘗試實施
我直接從 git-hub 使用Jhipster Registry 應用程序將其用作 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
我還在中央配置文件夾下創建了一個gateway.yml文件(網關是我試圖集中其配置的微服務示例應用程序之一,無論是尤里卡客戶端,數據源默認情況下屬於應用程序開發的所有內容.yml在我生成的Jhipster微服務網關應用程序中。)通過說明如下所示的所有配置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 如果我運行我的注冊表,它會正常運行,沒有任何問題。 如果我嘗試運行“網關”微服務應用程序而不定義它自己的配置文件(application-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
我很驚訝 eureka 實例是如何從該gateway.yml文件而不是數據源中獲取的,那么這里出了什么問題?
問題#2
在 gateway.app yml server.port:8888
中提到,但它是 spring-cloud-config-server 的端口還是微服務應用程序端口,例如 8083。我觀察到如果我嘗試將該端口從 8888 更改為 8083它在運行時給出錯誤無法找到發現客戶端,是什么問題,或者我仍然缺少配置方面的東西?
請讓我知道查詢是否足夠詳細,現在可以回復。
使用 jhipster-registry 的 JHipster 微服務架構絕對不需要 Docker,您的用例得到很好的支持,您遇到的問題只是由於您的配置錯誤。
gateway.yml
沒有正確縮進,因此datasource
的屬性名稱不匹配,這就是為什么您會收到有關無法找到 JDBC 驅動程序的錯誤。
eureka
塊中間的spring
塊完全破壞了它,無論如何,尤里卡配置由所有應用程序共享,因此它應該放在application-dev.yml
和application-prod.yml
中。
gateway.yml
與環境存儲庫中的任何其他文件(使用本機時central-config
文件夾)必須與本地 application.yml 文件的格式完全相同。
如果您對 YAML 文件不滿意,您可以切換到普通屬性。
關於本機存儲庫中的文件命名, Spring Cloud Config Server doc說:
如果存儲庫是基於文件的,則服務器從 application.yml(在所有客戶端之間共享)和 foo.yml(以 foo.yml 優先)創建一個環境。 如果 YAML 文件中包含指向 Spring 配置文件的文檔,則以更高的優先級應用這些文件(按照列出的配置文件的順序)。 如果存在特定於配置文件的 YAML(或屬性)文件,則這些文件的應用優先級也高於默認值。
所以基本上這意味着在你的central-config
文件夾中你應該有這些文件:
application.yml
:未設置配置文件時所有應用程序共有的所有屬性application-dev.yml
:設置 dev 配置文件時所有應用程序共有的所有屬性。 在這里,您將為 dev 放置 JWT 機密,為 dev Eureka 服務器(通常是本地主機)放置 urlapplication-prod.yml
:設置 prod 配置文件時所有應用程序共有的所有屬性。 這是您將 JWT 密碼用於 prod 的地方,url 用於 prod Eureka 服務器gateway.yml
:未設置配置文件時網關應用程序的所有屬性gateway-dev.yml
:設置 dev 配置文件時網關應用程序的所有屬性。 這是您將放置開發數據源的地方gateway-prod.yml
:設置 prod 配置文件時網關應用程序的所有屬性。 這是您將放置 prod 數據源的位置因此,當您的網關使用 dev 配置文件引導時,它將獲得 application.yml、application-dev.yml、gateway.yml 和 gateway-dev.yml 的組合
只有遵循命名約定{app name}-{profile}.yml
才能使用此機制
因此,將文件命名為application-dev-gateway.yml
只是意味着具有dev-gateway
配置文件的所有應用程序共有的屬性,這可能不是您的意思。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.