1. Introduction to Spring Boot Admin
spring boot admin github open source address: https://github.com/codecentric/spring-boot-admin
Its main function is to provide a simple WEB UI display based on Spring Boot Actuator.
2. Project usage:
1. Build a maven web project
2. Pom dependency configuration
<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-client</artifactId> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server</artifactId> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui</artifactId> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui-login</artifactId> </dependency>
Add the above configuration in pom.xml
admin server: spring-boot-admin-server, spring-boot-admin-server-ui
admin client: spring-boot-admin-starter-client (plus this item can monitor the operating status of the server itself. Other projects only need to introduce client to introduce monitoring)
Security: spring-boot-starter-security
Login verification: spring-boot-admin-server-ui-login (you can also add a simple login interface by yourself)
3. application.yml
info: app: name: imped version: v1.0.0 [html] view plain copylogging: file: "d:/logs/imard/boot.log" management: context-path: "/actuator" spring: application: name: "@pom.artifactId@" boot: admin: url: http://www.test.com:8080 profiles: active: -secure --- spring: profiles: insecure management: security: enabled: false security: basic: enabled: false --- spring: profiles: secure boot: admin: username: "${security.user.name}" password: "${security.user.password}" client: metadata: user.name: "${security.user.name}" user.password: "${security.user.password}" security: user: name: user password: pass Among them: spring.boot.admin.url declares the admin server address (other projects will actively register with admin monitoring through this url)
Basic information about info configuration app
www.test.com Mapping in native hosts
4. Application.java
@Configuration @EnableAutoConfiguration @EnableAdminServer public class Application extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Application.class); } public static void main(String[] args) { SpringApplication.run(Application.class, args); } }@EnableAdminServer Add this annotation to start monitoring
5. SecurityConfig
@Profile("secure") @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.formLogin().loginPage("/login.html").loginProcessingUrl("/login").permitAll(); http.logout().logoutUrl("/logout"); http.csrf().disable(); http.authorizeRequests() .antMatchers("/login.html", "/**/*.css", "/img/**", "/third-party/**").permitAll(); http.authorizeRequests().antMatchers("/api/**").permitAll().antMatchers("/**") .authenticated(); // Enable so that the clients can authenticate via HTTP basic for registering http.httpBasic(); } }Configure a basic security policy using Spring Security
6. Supervision and management
After 1 to 5 steps are configured, use the application to start the monitoring program.
After security verification through the http://www.test.com:8080/login.html monitoring login interface, as shown in the figure below:
Enter details to see specific project monitoring information (Details, Log, Metrics, Environment, Logging, JMX, Threads, Audit, Trace, Heapdump)
Summarize
The above is the method of adding admin monitoring in spring boot introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!