preface

At the end of the year, the project is basically finished, and I have some free time. I am ready to summarize the integration methods of various common plug-ins of SpringBoot, hoping to be helpful to you.

Today is the day to integrate SpringBootAdmin, so what does SpringBootAdmin do? To put it simply, it is a monitoring tool, at this time there are more intelligent students to question, since you can use the JDK with jConsole and JVisualVM monitoring, ask why use this. The answer is that the interface looks better.

SpringBootAdmin is neat and nice

Jvisualvm has a strong sense of age

Stop! SpringBootAdmin can view the basic information of all monitored Spring-Boot projects in the list. Detailed Health information, memory information, JVM information, garbage collection information, various configuration information (such as data source, cache list, hit ratio), and you can directly modify logger levels.

For details, go to Github. Github.com/codecentric…

Let’s get down to business.

1. Server construction

Configuration of pom. The XML

Create a new SpringBoot project and add it to the POM file

<dependencies> <! <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <! --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> </dependency> </dependencies>Copy the code

Configuring startup Classes

@SpringBootApplication @EnableAdminServer public class MonitorAdminApplication { public static void main(String[] args) { SpringApplication.run(MonitorAdminApplication.class, args); System.out.println("Admin monitor started successfully "); }}Copy the code

Configure security

Modify the application

server:
  port: 10005

spring:
  security:
    user:
      name: admin
      password: admin123
  boot:
    admin:
      context-path: /admin
Copy the code

Create a SecurityConfig WebSecurityConfigurerAdapter rewrite the configure class hierarchy (HttpSecurity HTTP) method

@Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, proxyTargetClass = true) public class SecurityConfig extends WebSecurityConfigurerAdapter { private final String adminContextPath; public SecurityConfig(AdminServerProperties adminServerProperties) { this.adminContextPath = adminServerProperties.getContextPath(); } @Override protected void configure(HttpSecurity httpSecurity) throws Exception { SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler(); successHandler.setTargetUrlParameter("redirectTo"); successHandler.setDefaultTargetUrl(adminContextPath + "/"); HttpSecurity. AuthorizeRequests () / / awarded to all static assets and public access to the login page. .antMatchers(adminContextPath + "/assets/**").permitAll() .antMatchers(adminContextPath + "/login").permitAll() AnyRequest ().authenticated().and() // Configure login and logout.formLogin().loginPage(adminContextPath + "/login") .successhandler (successHandler).and().logout().logouturl (adminContextPath + "/logout"). And () // Enable HTTP-Basic support. HttpBasic ().and().csrf().disable().headers().frameoptions ().disable(); httpBasic().http ().csrf().disable().headers().frameoptions ().disable(); }}Copy the code

Now you can start the project to see the effect localhost:10005/admin

You can already see the login screen. Log in and have a look

As you can see there is no project connection, look at the configuration of the client.

2. Client configuration

Configuration of pom. The XML

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

Configure the application

Add in the application.yml file

Boot: Admin: Client: # Enabling the Client enabled: True # set Spring Boot Admin Server address url: http://localhost:10005/admin instance: -- - IP: Username: admin password: admin123 Application: name: springbootadamin-test management: Endpoints: Web: # Actuator Root directory of apis provided. The default is/skeleton-base-path: / skeleton-exposure: # Specifies the endpoints that need to be opened. Set * to open all endpoints. Include: '*' endpoint: logfile: external-file:./logs/sys-console.logCopy the code

Then start the client project and see what happens.

Find that you already have an application instance, and then look at others.

This completes the integration of the entire SpringBootAdmin monitoring system.