Configure the spring framework on Apollo

Yagr Xu 2022-06-24 05:26:54 阅读数:90

configurespringframeworkapollo

Here is a brief introduction to how to migrate Spring Framework Configuration center for to Apollo

Focus on the fourth step , Today's record of stepping on the pit ~

1. Add pom dependency

<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>1.8.0</version>
</dependency>

2. Add Apollo config in bootstrap

app:
id: <my app id>
apollo:
meta: http://127.0.0.1:8080 # or ENV APOLLO_CONFIGSERVICE=http://127.0.0.1:8080
cluster: default
bootstrap:
enabled: true
eagerLoad:
enabled: true # This is more important ,eagerLoad Will be in Log Before load Information , Include server.port Etc
namespaces: auth.yaml,common.yaml

3. Enable Apollo Config in Java Code

import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
@EnableApolloConfig
public class DemoApplication {
}

4. If directly connected to config service Words , Use the following ENV

export APOLLO_CONFIGSERVICE=http://127.0.0.1:8080

5. hold config Put your information in Apollo On , And don't forget to post

Release Configuration

Start the program ~ juvenile ! The time for miracles has come ~

copyright:author[Yagr Xu],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/175/20210812193903615P.html