可能出现这个问题的原因是没有正确设置Apollo的配置或者缺少必要的依赖文件。可以尝试使用以下代码示例解决:
在Spring Boot项目中,在pom.xml中添加以下依赖:
com.ctrip.framework.apollo
apollo-client
1.6.1
然后在application.yml或者application.properties中添加以下配置:
# Apollo配置
apollo:
# MetaServer服务地址
meta: http://localhost:8080
# 命名空间
namespace: application
其中,MetaServer服务地址需要根据实际情况进行配置。最后,在项目启动类中,添加以下代码:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
Config config = ConfigService.getAppConfig();
System.out.println(config.getProperty("foo", "default"));
}
}
运行项目后,即可生成Apollo目录。
上一篇:Apollo模块有时未调用请求。