国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - SpringCloud2020 bootstrap 配置文件失效的解決方法

SpringCloud2020 bootstrap 配置文件失效的解決方法

2021-08-05 11:09馮文議 Java教程

這篇文章主要介紹了SpringCloud2020 bootstrap 配置文件失效的解決方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

Spring Cloud 2020版本 bootstrap 配置文件(properties 或者 yml)無效

如何解決?

 

背景介紹

微服務是基于Spring Cloud框架搭建的,Spring Cloud Config作為服務配置中心。

業務服務只配置服務名稱、啟用環境和config的URL地址,其他都配置在配置中心,例如服務端口、服務注冊中心地址等??稍陂_發環境(dev)、測試環境(test)和生產環境(prod)分別配置。

所以預想的啟動流程是:先加載配置文件,再啟動服務。

之前的做法是,將配置文件名稱改為:bootstrap.properties。

問題

之前直接就可以用,而現在,啟動的端口是8080,明顯沒有加載到bootstrap.properties文件,我以為我的文件名字寫錯了,核對了幾次,確認無誤,我猜想估計是bootstramp.properties配置文件沒有生效。

之前的版本:

  • spring boot 2.3.1.RELEASE
  • spring cloud Hoxton.SR4

當前版本:

  • spring boot 2.4.2
  • spring cloud 2020.0.1

查找原因

根據上面出現的問題,我使用百度搜索了下,大概的原因知道了:從Spring Boot 2.4版本開始,配置文件加載方式進行了重構。

另外也有配置的默認值變化,如下:

Spring Boot 2.3.8.RELEASE

?
1
2
3
4
5
package org.springframework.cloud.bootstrap;
public class BootstrapApplicationListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent>, Ordered {
 public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
  ConfigurableEnvironment environment = event.getEnvironment();
  if ((Boolean)environment.getProperty("spring.cloud.bootstrap.enabled", Boolean.class, true)) {

Spring Boot 2.4.2

?
1
2
3
4
5
package org.springframework.cloud.util;
public abstract class PropertyUtils {
 public static boolean bootstrapEnabled(Environment environment) {
  return (Boolean)environment.getProperty("spring.cloud.bootstrap.enabled", Boolean.class, false) || MARKER_CLASS_EXISTS;
 }

傳統解決方案

其實官網說得很明白??聪旅孢@段:

Config First Bootstrap
To use the legacy bootstrap way of connecting to Config Server, bootstrap must be enabled via a property or the spring-cloud-starter-bootstrap starter. The property is spring.cloud.bootstrap.enabled=true. It must be set as a System Property or environment variable. Once bootstrap has been enabled any application with Spring Cloud Config Client on the classpath will connect to Config Server as follows: When a config client starts, it binds to the Config Server (through the spring.cloud.config.uri bootstrap configuration property) and initializes Spring Environment with remote property sources.

The net result of this behavior is that all client applications that want to consume the Config Server need a bootstrap.yml (or an environment variable) with the server address set in spring.cloud.config.uri (it defaults to "http://localhost:8888").

兩個關鍵點:

1、加一個依賴:spring-cloud-starter-bootstrap

?
1
2
3
4
<dependency>
 <groupId>org.springframework.cloud</groupId>
 <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

2、加一個配置:spring.cloud.config.uri

?
1
2
3
4
5
6
7
8
9
10
11
12
bootstrap.properties
 
# 應用名稱
spring.application.name=erwin-cloud-user
# 啟用環境
spring.profiles.active=dev
 
# 配置文件
spring.cloud.config.label=${spring.application.name}
spring.cloud.config.name=${spring.application.name}
spring.cloud.config.profile=${spring.profiles.active}
spring.cloud.config.uri=http://localhost:9000

解決方案

現在,你只需要這樣:

?
1
2
3
4
5
6
7
8
9
10
11
12
application.properties
 
# 應用名稱
spring.application.name=erwin-cloud-user
# 啟用環境
spring.profiles.active=dev
 
spring.config.import=optional:configserver:http://localhost:9000
 
spring.cloud.config.label=${spring.application.name}
spring.cloud.config.name=${spring.application.name}
spring.cloud.config.profile=${spring.profiles.active}

到此這篇關于SpringCloud2020 bootstrap 配置文件失效的解決方法的文章就介紹到這了,更多相關SpringCloud2020 bootstrap 配置內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!

原文鏈接:https://segmentfault.com/a/1190000039185130

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 欧美一区二区在线播放 | 色婷婷精品国产一区二区三区 | 久久久久国产精品免费免费搜索 | 最近免费观看高清韩国日本大全 | 亚洲精品一区二区三区在线 | 国产黄色在线网站 | 日韩av在线免费 | 成年人在线观看免费视频 | 国产有码 | a毛片视频 | 激情六月婷 | 婷婷网址| 国产精品久久久久久久久久久久久久 | 丁香婷婷综合激情五月色 | 久久亚洲美女 | 激情国产 | 色屁屁影院 | 国产精品美女久久久久av麻豆 | 仙人掌旅馆在线观看 | 成年人在线看 | 国产一级片 | 日本aⅴ毛片成人实战推荐 伊人久久在线 | 日韩和的一区二在线 | 成人不卡视频 | 欧美一级片在线播放 | 成人免费大片黄在线播放 | 午夜精品久久久久久久久久久久久 | 九色在线观看 | 99视频在线免费观看 | 国产免费自拍av | 精品99久久久久久 | 亚洲综合自拍 | 伊人网在线视频免费观看 | 亚洲精品偷拍自拍 | www.亚洲黄色 | 91婷婷射| 99精品视频免费观看 | 亚洲一区二区三 | 久久人人爽爽爽人久久久 | www亚洲精品| 免费日韩 |