栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java > SpringBoot

SpringBoot 2.x 开发案例之整合Spring Boot Admin

SpringBoot 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringBoot 2.x 开发案例之整合Spring Boot Admin

前言

Spring Boot Admin 就是将 Spring Boot Actuator中提供的endpoint信息可视化表示,并且可以通过邮件、Telegram、Hipchat等发送告警消息。

集成

注意一定要版本对应,否则会出现意想不到的问题,建议使用Srping Boot Admin 2.0+以上版本,可以多语言切换。

父项目

pom.xml引入:


 admin-server
 admin-client



      org.springframework.boot
      spring-boot-starter-parent
      2.2.2.RELEASE
      


      
     org.springframework.boot
     spring-boot-starter-web
     
  
      org.springframework.boot
      spring-boot-starter-tomcat
  
     
      
      
     org.springframework.boot
     spring-boot-starter-jetty
      

监控服务端

pom.xml引入:

admin-server

      
   de.codecentric
   spring-boot-admin-starter-server
   2.2.1
      
      
      
   org.springframework.boot
   spring-boot-starter-security
      
      
      
   org.springframework.boot
   spring-boot-starter-mail
      

application.properties配置文件:

# 爪哇笔记:https://blog.52itstyle.vip
server.port=9000
spring.application.name=SpringBootAdmin
spring.security.user.name=admin
spring.security.user.password=admin
spring.boot.admin.monitor.status-interval = 10000
spring.boot.admin.monitor.info-interval = 10000

spring.mail.host = smtp.163.com
spring.mail.username = 13188888888@163.com
spring.mail.password = 2020
spring.boot.admin.notify.mail.from = 13188888888@163.com
spring.boot.admin.notify.mail.to = 88888888@qq.com

启动类:

@Configuration
@EnableAutoConfiguration
@EnableAdminServer
public class Application {

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

    @Configuration
    public static class SecuritySecureConfig extends WebSecurityConfigurerAdapter {

 private final AdminServerProperties adminServer;

 public SecuritySecureConfig(AdminServerProperties adminServer) {
     this.adminServer = adminServer;
 }

 @Override
 protected void configure(HttpSecurity http) throws Exception {
     SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
     successHandler.setTargetUrlParameter("redirectTo");
     successHandler.setDefaultTargetUrl(this.adminServer.path("/"));

     http.authorizeRequests()
      .antMatchers(this.adminServer.path("/assets/**")).permitAll()
      .antMatchers(this.adminServer.path("/login")).permitAll()
      .anyRequest().authenticated()
      .and()
      .formLogin().loginPage(this.adminServer.path("/login")).successHandler(successHandler).and()
      .logout().logoutUrl(this.adminServer.path("/logout")).and()
      .httpBasic().and()
      .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/**"))
      )
      .and()
      .rememberMe().key(UUID.randomUUID().toString()).tokenValiditySeconds(1209600);
 }
    }
}

监控客户端

pom.xml引入:

admin-client

    
 de.codecentric
 spring-boot-admin-starter-client
 2.2.1
    

application.properties配置文件:

# 爪哇笔记:https://blog.52itstyle.vip
spring.boot.admin.client.instance.name = 007
spring.boot.admin.client.url= http://localhost:9000
management.endpoints.web.exposure.include=*
spring.boot.admin.client.username = admin
spring.boot.admin.client.password = admin
spring.boot.admin.client.period = 10000
spring.boot.admin.client.connect-timeout = 5000
spring.boot.admin.client.read-timeout = 5000
spring.boot.admin.client.instance.service-url = http://localhost:8080
监控界面


小结

不得不说,2.X 版本还是很美观大气上档次的,并且监控告警功能齐全,小微服务必备神器。

参考

https://blog.52itstyle.vip/archives/5052/

https://github.com/codecentric/spring-boot-admin

https://codecentric.github.io/spring-boot-admin/2.2.1/

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/234226.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号