Small knowledge, big challenge! This paper is participating in theEssentials for programmers”Creative activities

This paper has participated inProject DigginTo win the creative gift package and challenge the creative incentive money.

📖 preface

Good attitude, not so tired. In a good mood, all you see is beautiful scenery.Copy the code

"If you can't solve a problem for a while, use this opportunity to see your limitations and put yourself out of order." As the old saying goes, it's easy to let go. If you are distracted by something, learn to disconnect. Cut out the paranoia, the trash in the community, and get rid of the negative energy. Good attitude, not so tired. In a good mood, all you see is beautiful scenery.

🚓Add the Spring Boot Admin Server launcher to your dependencies:


		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>

        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
            <version>2.3.1</version>
        </dependency>

        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
        </dependency>
Copy the code

1. Start the class to add annotations


@Slf4j
@EnableAdminServer
@EnableDiscoveryClient
@SpringBootApplication
Copy the code

PS: By adding@EnableAdminServerTo the configurationSpring Boot Admin Serverconfiguration

2. ymlconfiguration

spring:
  application:
    # app name
    name: dream-monitor
  Allow overriding bean definitions
  main:
    allow-bean-definition-overriding: true
  cloud:
    nacos:
      config:
        server-addr: ${spring.cloud.nacos.discovery.server-addr}
        group: DEFAULT_GROUP
        namespace: # namespace id
        enabled: true
        encode: UTF-8
        username: nacos
        # nacos password
        password: # nacos password
        max-retry: 32
        file-extension: yml
      discovery:
        server-addr: # nacos address
  # Application environment
  profiles:
    active: dev
Copy the code

3. Start


At this point,SpringBoot Admin ServerThe configuration is complete. Start the module.

4. SPRING BOOT ADMIN CLIENTClient Access


You can use anySpring Cloud DiscoveryClientImplementation (Eureka, Consul, Nacos), here withSpringCloud Alibaba NacosAs an example.

1. Add dependencies to your project:

<dependency>
     <groupId>de.codecentric</groupId>
     <artifactId>spring-boot-admin-starter-client</artifactId>
     <version>2.3.1</version>
</dependency>
Copy the code

2. Add@EnableDiscoveryClientGo to configuration to enable discovery:

@SpringBootApplication
@EnableDiscoveryClient
Copy the code

3. TellNacosWhere can clients find the service registry:

bootstrap.yml

spring:
  application:
    name: gateway
  cloud:
    nacos:
      discovery:
        server-addr: Nacos address
  profiles:
    active: dev
server:
  port: 9999
Copy the code

application.yml

management:
    endpoints:
      web:
        exposure:
          include: "*"  
    endpoint:
      health:
        show-details: ALWAYS
Copy the code

PS: As with Spring Boot 2, most endpoints are not exposed over HTTP by default, and we expose all endpoints. For production, you should carefully choose which endpoints to expose.

4. StartClientTo see the effect


Finally, thank you for your patience. The next section is how to addsecuritySafe password, leave a point like collection is your biggest encouragement to me!


🎉 summary:

  • For more references, see here:The Blog of Chan Wing Kai

  • Like the small partner of the blogger can add a concern, a thumbs-up oh, continue to update hey hey!