Today we need to use spring-boot-admin to monitor the spring-boot project. The previous version on the web is too old to summarize now. The current version of spring-boot-admin is 2.1.4, and the spring-boot project is 2.1.4.release.

Creating a Server project

1. Create the boot-admin-server project and import the Jar package

< properties > < Java version > 1.8 < / Java version > < spring - the boot - admin. Version > 2.1.4 < / spring - the boot - admin. Version > < / properties >  <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> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope>
    </dependency>
    
    <dependency>
    	<groupId>org.springframework.boot</groupId>
    	<artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    </dependencies>
    
<dependencyManagement>
    <dependencies>
    	<dependency>
    		<groupId>de.codecentric</groupId>
    		<artifactId>spring-boot-admin-dependencies</artifactId>
    		<version>${spring-boot-admin.version}</version>
    		<type>pom</type>
    		<scope>import</scope>
    	</dependency>
    </dependencies>
</dependencyManagement>
Copy the code

2. Configure Spring-Security

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; import org.springframework.security.web.csrf.CookieCsrfTokenRepository; import de.codecentric.boot.admin.server.config.AdminServerProperties; @Configuration public class SecuritySecureConfig extends WebSecurityConfigurerAdapter { private final String adminContextPath; 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()
        		.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
        		.ignoringAntMatchers(adminContextPath + "/instances", adminContextPath + "/actuator/**"); }}Copy the code

After configuration, access requires a user name and password

3. Configuration files

server.port=8070
spring.security.user.name=admin
spring.security.user.password=123456

Copy the code

Modify a port to prevent the port from being occupied and specify the user name and password

4. Start the program configuration

import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import de.codecentric.boot.admin.server.config.EnableAdminServer; @SpringBootApplication @EnableAdminServer public class BootAdminServerApplication { public static void main(String[] args) { SpringApplication.run(BootAdminServerApplication.class, args); }}Copy the code

The above procedures can be started

Configuring the Client Project

1, normal is their own project, here is a case project boot-admin-client, add Jar package

< properties > < Java version > 1.8 < / Java version > < spring - the boot - admin. Version > 2.1.4 < / spring - the boot - admin. Version > < / properties >  <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope>
    </dependency>
    <dependency>
    	<groupId>org.springframework.security</groupId>
    	<artifactId>spring-security-test</artifactId>
    	<scope>test</scope>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
    	<dependency>
        	<groupId>de.codecentric</groupId>
        	<artifactId>spring-boot-admin-dependencies</artifactId>
        	<version>${spring-boot-admin.version}</version>
        	<type>pom</type>
        	<scope>import</scope>
    	</dependency>
    </dependencies>
</dependencyManagement>
Copy the code

2. Configuration files

Only the health and INFO nodes are enabled by default
management.endpoints.web.exposure.include=*
Remove configuration file information
#management.endpoints.web.exposure.exclude=configprops
Details are not displayed by default
management.endpoint.health.show-details=always

# Server addressSpring. The boot. Admin. Client. Url = http://127.0.0.1:8070# address of this clientSpring. The boot. Admin. Client. The instance. The service - url = http://127.0.0.1:8080Verify the Admin user name and password
spring.boot.admin.client.username=admin
spring.boot.admin.client.password=123456

spring.security.user.name=client
spring.security.user.password=123456
Copy the code

3, start the main program, you can access to view information at http://127.0.0.1:8070

conclusion

Generally speaking, the configuration file is relatively simple, mainly because some attribute names have been changed, it is easy to invalid, mainly check the official website to obtain the latest configuration can be used quickly.