
下载Apollohttps://www.apolloconfig.com/#/zh/deployment/quick-start安装文档操作步骤来先安装Java环境 https://www.java.com/zh-CN/安装成功 验证 安装成功会有版本信息java-versionMySQL如果使用 H2 内存数据库/H2 文件数据库则无需 MySQL可以跳过此步骤https://dev.mysql.com/downloads/mysql/安装mysql安装好后 测试是否可以连接找到apollo 的这个两个文件 执行这个两个sql注意事项apollo 服务端进程需要分别使用8070, 8080, 8090端口请确保这3个端口当前没有被使用。安装NSSMNon-Sucking Service Manager把 java 注册成系统服务支持崩溃自动重启、开机自启注册 Apollo 为 Windows 服务安装地址\nssm.exeinstallApollo在弹出的窗口里填写#查看java地址where.exejava下载Quick Start安装包https://github.com/apolloconfig/apollo-quick-start下载好的文档 解压 放入指定的路径注意 NSSM 要加 .\ 前缀你现在在 nssm 的 win64 目录里cdxxxx\nssm.exeinstallApolloPath你实际的 java 路径\bin\java.exStartup directoryapollo jar 所在目录 如D:\Program Files (x86)\apolloArguments填入以下一整串一行cdD:\Program Files (x86)\nssm-2.24-101-g897c7ad\win64.\nssm.exeinstallApolloC:\你的java路径\java.exe-Dspring.profiles.activegithub,database-discovery,auth -Dspring.h2.console.enabledfalse -Dspring.config.datasource.urljdbc:mysql://localhost:3306/ApolloConfigDB?useSSLfalsecharacterEncodingutf8serverTimezoneAsia/Shanghai -Dspring.config.datasource.usernameroot -Dspring.config.datasource.password你的密码 -Dspring.portal.datasource.urljdbc:mysql://localhost:3306/ApolloPortalDB?useSSLfalsecharacterEncodingutf8serverTimezoneAsia/Shanghai -Dspring.portal.datasource.usernameroot -Dspring.portal.datasource.password你的密码 -jar D:\apollo\apollo-all-in-one.jar.\nssm.exesetApollo AppDirectory D:\apollo .\nssm.exesetApollo AppStdout D:\apollo\apollo.log .\nssm.exesetApollo AppStderr D:\apollo\apollo.log Start-Service Apollo Start-Sleep60Get-Service Apollo浏览器访问 http://localhost:8070apollo / admin 登录。想确认数据确实在 MySQL 里mysql安装地址\bin\mysql.exe-uroot-p-eUSE ApolloPortalDB; SELECT username FROM Users;创建**创建c# 项目 net10**安装Com.Ctrip.Framework.Apollo.ConfigurationProgram.csusing Com.Ctrip.Framework.Apollo;var builderWebApplication.CreateBuilder(args);// Add services to the container. //添加apollo builder.Configuration.AddApollo(builder.Configuration.GetSection(apollo));builder.Services.AddControllers();// Learnmoreabout configuring OpenAPI at https://aka.ms/aspnet/openapi builder.Services.AddOpenApi();var appbuilder.Build();// Configure the HTTP request pipeline.if(app.Environment.IsDevelopment()){app.MapOpenApi();}app.UseHttpsRedirection();app.UseAuthorization();app.MapControllers();app.Run();WeatherForecastControllerusing Microsoft.AspNetCore.Mvc;namespace WebApplication1.Controllers{[ApiController][Route([controller])]#[Route(api/[controller])]public class WeatherForecastController:ControllerBase{privatereadonlyIConfiguration _config;public WeatherForecastController(IConfiguration config){_configconfig;}private staticreadonlystring[]Summaries[Freezing,Bracing,Chilly,Cool,Mild,Warm,Balmy,Hot,Sweltering,Scorching];//[HttpGet(NameGetWeatherForecast)]// GetWeatherForecast[HttpGet(GetWeatherForecast)]// WeatherForecast/GetWeatherForecast public IEnumerableWeatherForecastGet(){var AIConfigjson_config.GetValuestring(AIConfig);var IsShare_config.GetValuebool(IsShare);returnEnumerable.Range(1,5).Select(indexnew WeatherForecast{DateDateOnly.FromDateTime(DateTime.Now.AddDays(index)), TemperatureCRandom.Shared.Next(-20,55), SummarySummaries[Random.Shared.Next(Summaries.Length)]}).ToArray();}}}