13、 Spring boot elegant integration of spring boot admin program monitoring



We know that the project monitoring is particularly important, but if we use the jconsole and JVM of JDK, it will be very tedious, and the interface is not very friendly. We used the spring boot project before, but we didn’t have a good monitoring of the project. In the spring family, spring boot admin can help us monitor the microservice project.

Spring boot admin is a monitoring tool for UI beautification encapsulation of spring boot’s activator interface. It can browse the basic information, detailed health information, memory information and JVM of all monitored spring boot projects in the list Information, garbage collection information, various configuration information (such as data source, cache list and hit rate), etc., can also directly modify the level of the logger.

Spring boot admin is divided into server and client. The server is a separate microservice, which is used to check the operation of the monitored projects. The client is our microservice projects one by one. So if we want our project to be monitored by the server, we need to register our service to the server.

OK, let’s try it.


First, let’s build the server of spring boot admin, which says that the server is a separate project. So we create a new springboot project. After creation, let’s make some changes.


In the POM file, we introduce the following dependencies

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <relativePath/> <!-- lookup parent from repository -->
    <description>springbootadmin project for Spring Boot</description>









Above is my whole POM file. You can see that I have introduced web, admin starter server and security.
If you think about other things, you can only reference admin starter server to achieve the effect.

Startup class

Add @ enableadminserver annotation to our startup class. If not, the project can start normally, but nothing can be seen. @The role of the enableadminserver annotation is to start monitoring.

public class SpringbootadminApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringbootadminApplication.class, args);

Configure security

After this configuration, you can start the project, but we won’t start it here, because we learned in the previous section, spring boot security. Here we use it.
We have introduced security before. Next, we will add configuration in application


Indicates that this user can access it. In addition, we create a securityconfig class to inherit the websecurityconfigureradapter and override the configure (httpsecurity HTTP) method. The code is as follows:

public class SecurityConfig extends WebSecurityConfigurerAdapter {
    protected void configure(HttpSecurity http) throws Exception {
        SavedRequestAwareAuthenticationSuccessHandler successHandler
                = new SavedRequestAwareAuthenticationSuccessHandler();

Now let’s start the project. Enter after starting project


Will jump to the login interface, enter the home page is nothing now.
13、 Spring boot elegant integration of spring boot admin program monitoring


Now we can configure the server. Now let’s configure the client. We can either find a spring boot project or create a new one ourselves.


First, we add admin client dependency to POM file. Note that the version here needs to be the same as that of server.



Then we add the following configuration to the application.properties file.


Spring.boot.admin.client.url points to the project interface path of our server.
Management.endpoints.web.exposure.include means that all ports are exposed and can be monitored.
Spring.application.name indicates the display name of the project on spring boot admin.
Spring.boot.admin.client.username and password are the set user name and password. It should be noted that if there is no integrated security in admin server, you can register without configuring the user name and password, which can be monitored in the server, but if the security is integrated in admin server, you need to ensure the user name and server configured in the client The user name and password configured in are consistent.


With the above configuration, you can register the project to admin server. Let’s start the project.

Now there is another problem. If our project itself is an integrated security framework, such as security, without login, we can’t access the interface. How can such a project be monitored by admin server? For example, we registered the security demo in the last section. Although it is monitored, it is a failed state.
13、 Spring boot elegant integration of spring boot admin program monitoring
It can be seen that it is not difficult to find problems, that is, the monitoring interface is also blocked by the project itself, so it leads to a failure state. How to modify it? In fact, it’s better to deal with it. Just let these interfaces go. We add configure (httpsecurity HTTP) in the securityconfig class of the project
13、 Spring boot elegant integration of spring boot admin program monitoring
The code is as follows:

    protected void configure(HttpSecurity http) throws Exception {
            .antMatchers("/", "/hello").permitAll()
            .antMatchers( "/actuator/**").permitAll()
            .antMatchers( "/instances").permitAll()

In this way, we restart the project and find that the monitoring is successful.
13、 Spring boot elegant integration of spring boot admin program monitoring

Off the coast

So far, we have also demonstrated the general functions of spring boot admin.

Upload the code to GitHub:

Follow up

Welcome to the public’s official account of “programmers love yogurt”.

Share all kinds of learning materials, including Java, Linux, big data, etc. The materials include video documents and source code, and share the high-quality technical blog articles delivered by myself and others.

If you like, remember to pay attention and share Mei

13、 Spring boot elegant integration of spring boot admin program monitoring