spring boot 添加admin監(jiān)控的方法
一、Spring Boot Admin簡(jiǎn)介
spring boot admin github開(kāi)源地址:https://github.com/codecentric/spring-boot-admin
它主要的作用是在Spring Boot Actuator的基礎(chǔ)上提供簡(jiǎn)潔的WEB UI展示。
二、項(xiàng)目使用:
1、搭建一個(gè)maven web項(xiàng)目
2、pom依賴配置
<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>
在pom.xml中添加上以上配置
admin服務(wù)端:spring-boot-admin-server、spring-boot-admin-server-ui
admin客戶端:spring-boot-admin-starter-client (加上該項(xiàng)能監(jiān)控服務(wù)端自身的運(yùn)行狀態(tài),其他項(xiàng)目只需要引入client就可以引入監(jiān)控)
安全:spring-boot-starter-security
登錄驗(yàn)證:spring-boot-admin-server-ui-login (也可以自行添加簡(jiǎn)單的登錄界面)
3、application.yml
info:
app:
name: imard
version: v1.0.0
[html] view plain copy
logging:
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
其中:spring.boot.admin.url聲明admin服務(wù)端地址(其他項(xiàng)目會(huì)通過(guò)這個(gè)url主動(dòng)的注冊(cè)到admin監(jiān)控中)
info配置app的基本信息
www.test.com 在本機(jī)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 添加上該注解啟動(dòng)監(jiān)控
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();
}
}
使用Spring Security配置一個(gè)基本的安全策略
6、監(jiān)管管理
配置完1~5個(gè)步驟以后,使用application啟動(dòng)監(jiān)控程序。
通過(guò)http://www.test.com:8080/login.html監(jiān)控登錄界面進(jìn)行安全驗(yàn)證后,如下圖:

進(jìn)入details就可以看到具體的項(xiàng)目監(jiān)控信息(Details、Log、Metrics、Environment、Logging、JMX、Threads、Audit、Trace、Heapdump)
總結(jié)
以上所述是小編給大家介紹的spring boot 添加admin監(jiān)控的方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
springboot?全局異常處理和統(tǒng)一響應(yīng)對(duì)象的處理方式
這篇文章主要介紹了springboot?全局異常處理和統(tǒng)一響應(yīng)對(duì)象,主要包括SpringBoot 默認(rèn)的異常處理機(jī)制和SpringBoot 全局異常處理,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-06-06
java中public class與class的區(qū)別詳解
以下是對(duì)java中public class與class的區(qū)別進(jìn)行了分析介紹,需要的朋友可以過(guò)來(lái)參考下2013-07-07
Mockito mock Kotlin Object類方法報(bào)錯(cuò)解決方法
這篇文章主要介紹了Mockito mock Kotlin Object類方法報(bào)錯(cuò)解決方法,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-09-09
JAVA技術(shù)實(shí)現(xiàn)上傳下載文件到FTP服務(wù)器(完整)
這篇文章主要介紹了JAVA技術(shù)實(shí)現(xiàn)上傳下載文件到FTP服務(wù)器(完整),本文使用 Apache Jakarta Commons Net(commons-net-3.3.jar) 基于FileZilla Server服務(wù)器實(shí)現(xiàn)FTP服務(wù)器上文件的上傳/下載/刪除等操作,需要的朋友可以參考下2015-07-07
SpringBoot+Vue跨域配置(CORS)問(wèn)題得解決過(guò)程
在使用 Spring Boot 和 Vue 開(kāi)發(fā)前后端分離的項(xiàng)目時(shí),跨域資源共享(CORS)問(wèn)題是一個(gè)常見(jiàn)的挑戰(zhàn),接下來(lái),我將分享我是如何一步步解決這個(gè)問(wèn)題的,包括中間的一些試錯(cuò)過(guò)程,希望能夠幫助到正在經(jīng)歷類似問(wèn)題的你2024-08-08

