Series of articles
@TOC
preface
I. Main points of this paper
Following this article, we have briefly demonstrated Springboot’s integration with the Apollo configuration center and demonstrated how to obtain business configuration. This article will show you how to make mysql, Redis, ES, Kafka, etc., hosted by Apollo to make your project look cleaner and more secure. A complete catalog of articles in the series
-
Apollo configuration Center
-
Springboot integrates Apollo Client
-
springboot + mybatis + Hikari + elasticsearch + redis + dubbo + apollo
Second, development environment
- JDK 1.8
- Maven 3.6.2
- Springboot 2.4.3
- Apollo, version 1.8.1
- Apollo cleint 1.8.0 comes with
- idea 2020
Install Apollo server
Reference: “Build large Distributed Services (15) Docker build development environment installation Apollo”
Iv. Increase Apollo dependence
SpringBoot integration Apollo Client Configuration Center
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>1.8.0 comes with</version>
</dependency>
Copy the code
Modify the configuration file
1, modify the application-dev.properties file, and modify the corresponding configuration file. Delete kafka, mysql, es, redis, and Apollo configurations.
#################### LOG ####################
logging.file.path=./logs
#################### apollo ####################
app.id=member-config
apollo.meta=http://9.135.xxx.xxx:8080
apollo.bootstrap.enabled=true
apollo.bootstrap.eagerLoad.enabled=true
Copy the code
2, for dev environment, upload kafka, mysql, ES, Redis configuration to Apollo, remember the key publish button.
Vi. Modify the project code
Modify ApolloDemoApplication @enableApolloConfig to enable configuration center.
@EnableApolloConfig
@SpringBootApplication
public class ApolloDemoApplication {
public static void main(String[] args) { SpringApplication.run(ApolloDemoApplication.class, args); }}Copy the code
2. Add IndexController and call MemberService.
@RestController
public class IndexController {
@Resource
private MemberService memberService;
@GetMapping("/get")
public Result get(a) {
TblMemberInfo member = new TblMemberInfo();
member.setUid(8888L);
TblMemberInfo ret = memberServce.get(member);
returnResult.ok(ret); }}Copy the code
Seven, run it
Localhost :8080/get: start the project normally, and get the redis cache.
Eight, summary
So far, we have sent configurations such as Redis, Kafka, ES, and Dubbo to Apollo for hosting. As long as we strictly control the configuration permissions in the production environment, we can avoid account password leakage and database deletion. Next article “Building a Large Distributed Service (18) SpringBoot Project customizing our Scaffolding”
Add me to exchange learning!