Cloud foundry 无法使用Steeltoe中的配置服务器服务从GIT存储库读取属性键值
我无法从dot net core 2.1应用程序的steeltoe中的git读取属性值 从我的客户机应用程序中,我想根据应用程序的环境读取Git存储库中不同环境属性文件(如foo-development.properties/foo-Production.properties)的属性文件 查找下面的代码以读取数据 Program.cs:Cloud foundry 无法使用Steeltoe中的配置服务器服务从GIT存储库读取属性键值,cloud-foundry,asp.net-core-2.1,pcf,configserver,steeltoe,Cloud Foundry,Asp.net Core 2.1,Pcf,Configserver,Steeltoe,我无法从dot net core 2.1应用程序的steeltoe中的git读取属性值 从我的客户机应用程序中,我想根据应用程序的环境读取Git存储库中不同环境属性文件(如foo-development.properties/foo-Production.properties)的属性文件 查找下面的代码以读取数据 Program.cs: public static IWebHostBuilder CreateWebHostBuilder(string[] args) => We
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseCloudFoundryHosting(5000)
.ConfigureAppConfiguration(b => b.AddConfigServer(new LoggerFactory().AddConsole(LogLevel.Trace)))
.AddCloudFoundry()
.UseUnityServiceProvider()
.UseStartup<Startup>();
Git存储库中的myclient.properties和myclient-development.properties文件
foo: Test
我已在定义的git URL中提交此文件。但我无法在客户端应用程序中获取消息属性
请在这方面帮助我。提前谢谢。PCF上的Spring Cloud Config Server需要授权交互。在Steeltoe的2.1版中,该授权不是在Steeltoe.Extensions.ConfigServer*中执行的,而是在Pivotal.Extensions.ConfigServer*中执行的* 对于ConfigServer NuGet参考和
使用program.cs
中的语句,请将“Steeltoe”更改为“Pivotal”,您应该都已设置好
通过此更改,您还可以删除WebHostBuilder
上的.AddCloudFoundry
,因为云铸造配置提供程序的关键版本将为您添加此功能。这是在PCF或本地工作站上运行配置服务器的情况下进行的吗?您正在使用哪个ConfigServer nuget软件包?您是否有任何相关的日志条目可用?是的。我正在PCF中运行配置。我使用下面的nuget包。Steeltoe.Extensions.Configuration.ConfigServer和Steeltoe.Extensions.Configuration.CloudFoundry
public class HomeController
{
private IOptionsSnapshot<ConfigServerData> IConfigServerData { get; set; }
private CloudFoundryServicesOptions CloudFoundryServices { get; set; }
private CloudFoundryApplicationOptions CloudFoundryApplication { get; set; }
private IConfigurationRoot Config { get; set; }
public HomeController(IOptionsSnapshot<ConfigServerData> configServerData, IConfigurationRoot config,
IOptions<CloudFoundryApplicationOptions> appOptions,
IOptions<CloudFoundryServicesOptions> servOptions)
{
if (configServerData != null)
IConfigServerData = configServerData;
// The ASP.NET DI mechanism injects these as well, see
// public void ConfigureServices(IServiceCollection services) in Startup class
if (servOptions != null)
CloudFoundryServices = servOptions.Value;
if (appOptions != null)
CloudFoundryApplication = appOptions.Value;
_service = service;
Config = config;
CreateConfigServerDataViewData();
}
private void CreateConfigServerDataViewData()
{
Console.WriteLine("Started...");
// IConfigServerData property is set to a IOptionsSnapshot<ConfigServerData> that has been
// initialized with the configuration data returned from the Spring Cloud Config Server
if (IConfigServerData != null && IConfigServerData.Value != null)
{
try
{
if (IConfigServerData != null)
{
Console.WriteLine("Not Null" + IConfigServerData.ToString());
}
}
catch(System.Exception ex) { }
var data = IConfigServerData.Value;
if (IConfigServerData.Value != null)
{
Console.WriteLine("Propertis " + data);
Console.WriteLine("Propertis " + data.foo);
}
Console.WriteLine("foo1 " + Config["Foo"]);
Console.WriteLine("foo2 " + Config["foo"]);
}
else
{
Console.WriteLine("There is no Properties Files available");
}
}
}
public class ConfigServerData
{
public string Bar { get; set; }
public string foo { get; set; }
// Optional data from vault
public string Vault { get; set; }
}
foo: Test