(1) Create a project in the Apollo configuration center.
(2) Add all relevant configurations of the corresponding environment to the configuration center, and then publish.
(3) Add dependencies to pom.xml
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>1.5.1</version>
</dependency>
(4) Add the @EnableApolloConfig annotation to the startup class
@SpringBootApplication
@EnableApolloConfig
public class PrpApplication {
public static void main(String[] args) {
SpringApplication.run(PrpApplication.class, args);
}
}
(5) Modify the original dev configuration file as follows
app:
id: xxx #你创建项目AppId
apollo:
meta: http://xxx.com/config/ #你的apollo配置中心地址(安装的时候有)
#cluster: myCluster #集群,没有可不写
#cacheDir: /opt/apolloDir #缓存文件
bootstrap:
enable: true
namespaces: application
env: DEV #对应apollo配置中心环境
After the configuration is complete, you can start the project and obtain the online configuration.