首先先安裝nuget組件:Steeltoe.Discovery.ClientCore
然后在ConfigureServices中進行注入
services.AddDiscoveryClient(Configuration);
Configure中引用
app.UseDiscoveryClient();
Appsettings中編寫
1 { 2 "Logging": { 3 "IncludeScopes": false, 4 "LogLevel": { 5 "Default": "Warning" 6 } 7 }, 8 "spring": { 9 "application": { 10 "name": "order11111" //注入的名稱 11 } 12 }, 13 "eureka": { 14 15 "client": { 16 "serviceUrl": "http://192.168.130.132:8761/eureka/", 17 "shouldRegisterWithEureka": true,//默認值是true 18 "shouldFetchRegistry": false,//設置指示客戶端不要獲取注冊表,因為該應用無需發現服務。它只想注冊服務 19 "validate_certificates": false 20 }, 21 "instance": { 22 "hostName": "192.168.130.148",//默認是在運行時自動確認的 不加上這個的話網關找不到服務 23 "port": 14802,//設置該服務中注冊的端口 24 "leaseRenewalIntervalInSeconds": 30, 25 "leaseExpirationDurationInSeconds": 90 26 } 27 28 29 } 30 }