Introduction to the

Springboot-admin provides a simple visual WEB UI based on the SpringBoot Actuator. It is a simple interface for managing Springboot applications. The functions are as follows:

  1. Display name/ ID and version number
  2. Display Online Status
  3. Logging Log level management
  4. JMX beans management
  5. Threads session and thread management
  6. Trace applies request tracing
  7. Application running parameters, such as:
    • Java System Properties
    • Java environment variable properties
    • Memory information
    • Spring Environment Properties

application

1. Create the Springboot-admin server

Introducing server-side POM dependencies:

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> < version > 2.0.1 < / version > < / dependency > < the dependency > < groupId > DE. Codecentric < / groupId > < artifactId > spring - the boot - admin server - UI < / artifactId > < version > 2.0.1 < / version > < / dependency > <! <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.jolokia</groupId> <artifactId>jolokia-core</artifactId> </dependency>Copy the code

Application. Yml configuration

server:
  port: 8080

#admin Specifies the user name and password for logging in
spring:
  application:
    name: admin-server

  #security User configuration
  security:
    user:
      name: admin
      password: admin

  boot:
    admin:
      context-path: /admin  
      discovery: true

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

New SecuritySecureConfig configuration:

import de.codecentric.boot.admin.server.config.AdminServerProperties; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; /** * @description: TODO(springboot-admin login configuration) * @author: Love gone with the wind DE boy * / @ Configuration public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {/ * * * - private * Define Admin context path */ private Final String adminContextPath; /** * Spring Boot Admin does not provide a default method because there are several ways to address authentication and authorization in distributed Web applications. By default, spring-boot-admin-server-UI provides a login page and a logout button. * Spring Security configuration * @param adminServerProperties */ Public SecuritySecureConfig(adminServerProperties adminServerProperties) { this.adminContextPath = adminServerProperties.getContextPath(); } @Override protected void configure(HttpSecurity http) throws Exception { SavedRequestAwareAuthenticationSuccessHandler  successHandler = new SavedRequestAwareAuthenticationSuccessHandler(); successHandler.setTargetUrlParameter("redirectTo");
        successHandler.setDefaultTargetUrl(adminContextPath + "/");

        http.authorizeRequests()
                .antMatchers(adminContextPath + "/assets/**").permitAll()
                .antMatchers(adminContextPath + "/login").permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()
                .logout().logoutUrl(adminContextPath + "/logout").and() .httpBasic().and() .csrf().disable(); }}Copy the code

Start class add @enableadMinServer annotation:

import de.codecentric.boot.admin.server.config.EnableAdminServer; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; /** * @author */ @enableAutoConfiguration @enableadMinServer @springBootApplication public class AdminServerApplication { public static void main(String[] args) { SpringApplication.run(AdminServerApplication.class, args); }}Copy the code

Start the Springboot project to access: IP :port/admin

2. Configure the client (monitored Springboot project)

Add dependencies to POM files:

<! --> <dependency> <groupId>de. Codecentric </groupId> < artifactId > spring - the boot - admin - starter - client < / artifactId > < version > 2.0.1 < / version > < / dependency > < the dependency > <groupId>org.jolokia</groupId> <artifactId>jolokia-core</artifactId> </dependency> <! -- web--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>Copy the code

Application. Yml configuration:

spring:
  boot:
    admin:
      client:
        url: http://localhost:8080/
        username: admin
        password: admin
        instance:
          prefer-ip: true  Register with IP
          
# Project health monitoring
management:
  endpoints:
    web:
      exposure:
        include: "*"
      base-path: /admin  # context-path server configuration
  endpoint:
    health:
      show-details: always

# Project information
info:
  app:
    # Customize display information
    name: "xxx"
    description: "xxx"
    version: "xx"
    environment: "xx"
    spring-boot-version: "2.0.1. RELEASE"
    spring-admin-version: "2.0.1"
  version: "1.0"
Copy the code