什么是 Spring Boot Admin?

codecentric 的 Spring Boot Admin 是一个社区项目,用于管理和监控您的Spring Boot ®应用程序。应用程序向我们的 Spring Boot Admin Client 注册(通过 HTTP)或使用 Spring Cloud ®(例如 Eureka、Consul)发现。UI 只是一个位于 Spring Boot Actuator 端点之上的 Vue.js 应用程序。

整合admin

版本

环境 版本
Spring Boot 2.4.6
JDK 13
Idea 2020.1

Server

pom

<properties><java.version>11</java.version><spring-boot-admin.version>2.3.1</spring-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></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>

yml

server:port: 8090servlet:contest-path: /
spring:application:name: admin-server

启动类

@SpringBootApplication
@EnableAdminServer
public class ServerApplication {public static void main(String[] args) {SpringApplication.run(ServerApplication.class, args);}}

Client

pom

<properties><java.version>11</java.version><spring-boot-admin.version>2.3.1</spring-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-client</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>

yml

server:port: 8091servlet:contest-path: /
spring:application:name: admin-clientboot:admin:client:url: http://localhost:8090
management:endpoints:web:exposure:include: '*'endpoint:health:show-details: always

测试

分别启动8090和8091项目,下图说明Client成功在Server端注册

打开浏览器输入http://localhost:8090回车

点击实例进入监控页面

功能不一一列举了,admin功能包括:

  • 显示 name/id 和版本号
  • 显示在线状态
  • Logging日志级别管理
  • JMX beans管理
  • Threads会话和线程管理
  • Trace应用请求跟踪
  • 应用运行参数信息,如:
  • Java 系统属性
  • Java 环境变量属性
  • 内存信息
  • Spring 环境属性

安全认证(security)

添加安全认证也很简单,需要在原来文件的基础上添加以下配置即可:

Server端

pom

        <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency>

SecuritySecureConfig

import de.codecentric.boot.admin.server.config.AdminServerProperties;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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 org.springframework.security.web.util.matcher.AntPathRequestMatcher;import java.util.UUID;/*** @ClassName : SecuritySecureConfig  //类名* @Description :   //描述* @Author :   //作者* @Date: 2021-06-04 15:31  //时间*/
@Configuration(proxyBeanMethods = false)
public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {private final AdminServerProperties adminServer;private final SecurityProperties security;public SecuritySecureConfig(AdminServerProperties adminServer, SecurityProperties security) {this.adminServer = adminServer;this.security = security;}@Overrideprotected void configure(HttpSecurity http) throws Exception {SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();successHandler.setTargetUrlParameter("redirectTo");successHandler.setDefaultTargetUrl(this.adminServer.path("/"));http.authorizeRequests((authorizeRequests) -> authorizeRequests.antMatchers(this.adminServer.path("/assets/**")).permitAll().antMatchers(this.adminServer.path("/actuator/info")).permitAll().antMatchers(this.adminServer.path("/actuator/health")).permitAll().antMatchers(this.adminServer.path("/login")).permitAll().anyRequest().authenticated()).formLogin((formLogin) -> formLogin.loginPage(this.adminServer.path("/login")).successHandler(successHandler).and()).logout((logout) -> logout.logoutUrl(this.adminServer.path("/logout"))).httpBasic(Customizer.withDefaults()).csrf((csrf) -> csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()).ignoringRequestMatchers(new AntPathRequestMatcher(this.adminServer.path("/instances"),HttpMethod.POST.toString()),new AntPathRequestMatcher(this.adminServer.path("/instances/*"),HttpMethod.DELETE.toString()),new AntPathRequestMatcher(this.adminServer.path("/actuator/**")))).rememberMe((rememberMe) -> rememberMe.key(UUID.randomUUID().toString()).tokenValiditySeconds(1209600));}// Required to provide UserDetailsService for "remember functionality"@Overrideprotected void configure(AuthenticationManagerBuilder auth) throws Exception {auth.inMemoryAuthentication().withUser(security.getUser().getName()).password("{noop}" + security.getUser().getPassword()).roles("USER");}}

yml

spring:security:user:name: 'admin'password: 'admin'

Client端

yml

spring:boot:admin:client:username: 'admin'password: 'admin'

测试

重新启动8090和8091项目

输入配置的用户名密码即可登录(此处是'admin')

邮件通知

admin支持邮件通知,配置如下:

(集成的邮箱以自己需求为主,此处以163邮箱为例)

Server端

pom

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-mail</artifactId>
</dependency>

yml

spring:mail:host: smtp.163.comusername: 发送人@163.compassword: 授权码boot:admin:notify:mail:enabled: trueto: 接收人@xx.comfrom: 发送人@163.com

获取授权码

已经拿到邮箱授权码的可以跳过此步骤

打开浏览器进入https://mail.163.com/登录163邮箱,成功后

这里需要扫描一下二维码发送短信开启(个人吐槽:有点坑短信费)

发送成功后选择'我已发送',把红圈里的授权码复制下来替换掉上面yml中的'授权码'文字

然后修改发送人和接收人邮箱地址,这里要注意一下,username和from必须是相同的邮箱,to是接收人的邮箱

修改完成后重启8090项目

测试

登录进入监控页面

此刻两个项目都正常运行,停止8091项目

启动8091项目

离线邮件

上线邮件


以上就是本篇的全部内容,下面附上github代码地址

springboot-admin

参考资料

1.https://codecentric.github.io/spring-boot-admin/current/#clustering-support

2.https://blog.csdn.net/forezp/article/details/86105850

Spring Boot整合Admin相关推荐

  1. spring boot整合spring security笔记

    最近自己做了一个小项目,正在进行springboot和spring Security的整合,有一丢丢的感悟,在这里分享一下: 首先,spring boot整合spring security最好是使用T ...

  2. RabbitMQ使用及与spring boot整合

    1.MQ 消息队列(Message Queue,简称MQ)--应用程序和应用程序之间的通信方法 应用:不同进程Process/线程Thread之间通信 比较流行的中间件: ActiveMQ Rabbi ...

  3. Spring Boot(十四):spring boot整合shiro-登录认证和权限管理

    Spring Boot(十四):spring boot整合shiro-登录认证和权限管理 使用Spring Boot集成Apache Shiro.安全应该是互联网公司的一道生命线,几乎任何的公司都会涉 ...

  4. 十一、Spring Boot整合Redis(一)

    Spring Boot整合Redis    1. SpringBoot+单例Redis 1)引入依赖 <dependency>     <groupId>org.springf ...

  5. Spring Boot 整合MyBatis(23)

    Spring Boot 整合MyBatis Spring Boot 整合 Druid 引入依赖 配置 application.yml pring Boot 整合 tk.mybatis 引入依赖 配置 ...

  6. Spring boot 整合Spring Security Jwt

    记录学习Spring boot 整合Spring Security Jwt 学习参考 – 慢慢的干货 https://shimo.im/docs/OnZDwoxFFL8bnP1c/read 首先创建S ...

  7. Spring Boot 整合 shiro 之盐值加密认证详解(六)

    Spring Boot 整合 shiro 之盐值加密认证详解 概述 不加盐认证 加入密码认证核心代码 修改 CustomRealm 新增获取密文的方法 修改 doGetAuthenticationIn ...

  8. Spring Boot整合Shiro + JSP教程(用户认证,权限管理,图片验证码)

    在此首先感谢**编程不良人**up主提供的视频教程 代码都是跟着up的视频敲的,遇到的一些问题也是通过CSDN博主提供的教程解决的,在此也感谢那些提供bug解决方案的前辈们~ 项目完整代码已经发布到g ...

  9. Spring Boot 整合 Shiro(三)Kaptcha验证码 附源码

    前言 本文是根据上篇<Spring Boot 整合Shiro(二)加密登录与密码加盐处理>进行修改,如有不明白的转上篇文章了解. 1.导入依赖 <!-- https://mvnrep ...

  10. Spring Boot 整合——Spring Boot整合kafka整合

    Spring Boot 整合之前的内容 项目名称 描述 地址 base-data-mybatis 整合mybatis-plus(实际上官方教程已经很多,只做了自定义插件) 未完成 base-jpa J ...

最新文章

  1. 读书:历史 -- 奥斯曼帝国六百年
  2. 关于学习Python的一点学习总结(54->集合->堆->双端队列)
  3. Java多线程笔记(零):进程、线程与通用概念
  4. git常用命令,分支操作,子模块
  5. 字符串的初值 正则表达式 sed应用
  6. 避免使用FOR –反假战役
  7. 修改表名_面试官:如何批量修改mysql表字段、表、数据库字符集和排序规则
  8. 返回顶部:js代码篇
  9. java书籍台湾翻译_《现代专业Javasctript 技术》一书中英文目录,翻译记录下来方便学习用...
  10. javascript使用事件委托
  11. 哪几所大学计算机软件方面是强项,计算机软件工程专业排名靠前的大学是那几所...
  12. scala的map映射问题
  13. Eureka的元数据
  14. 微型计算机控制第三版,清华大学出版社-图书详情-《微型计算机控制技术(第3版)》...
  15. [nlp] 双三次插值(BiCubic插值)
  16. android系统同时使用wifi和4g上网
  17. iOS开发 ----- 加载动画之牛顿摆的实现
  18. Java前方交会后方交会编程_单像空间后方交会和双像解析空间后方-前方交会的算法程序实现.doc...
  19. Mysql高级命令与概念
  20. 树莓派部署安装lnmp及可道云

热门文章

  1. 斯嘉丽约翰逊60张pdf什么时间的?_巩俐入围威尼斯电影节的作品叫什么?巩俐为什么被称为女皇?...
  2. vscode背景绿色配置
  3. 工业界中NLP(自然语言处理)算法工程师的核心竞争力是什么?
  4. 月末总结之大三大四规划(8.31)
  5. 多维度分析评价体系:高校教学质量大数据应用解决方案
  6. JavaScript 数组(二)数组练习
  7. 群发邮箱的软件哪个好?2021协议邮件群发软件推荐?
  8. 谷歌大脑组合模型霸榜 SuperGLUE,什么模型这么高?
  9. 百度地图和百度导航冲突问题
  10. linux 编译chromium,chromium(linux环境)指定版本下载和编译教程