第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

SpringBoot 2.x 開發(fā)案例之整合Spring Boot Admin

標(biāo)簽:
Java SpringBoot

前言

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

集成

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

父项目

pom.xml引入:

<modules>
        <module>admin-server</module>
        <module>admin-client</module>
</modules>

<parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.2.2.RELEASE</version>
      <relativePath/>
</parent>
<dependencies>
      <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
      </dependency>
      <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
      </dependency>
</dependencies>

监控服务端

pom.xml引入:

<artifactId>admin-server</artifactId>
<dependencies>
      <dependency>
          <groupId>de.codecentric</groupId>
          <artifactId>spring-boot-admin-starter-server</artifactId>
          <version>2.2.1</version>
      </dependency>
      <!--登录认证-->
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-security</artifactId>
      </dependency>
      <!--掉线发送邮件通知-->
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-mail</artifactId>
      </dependency>
</dependencies>

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

启动类:

/**
 * 系统监控
 * 爪哇笔记:https://blog.52itstyle.vip
 */
@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引入:

<artifactId>admin-client</artifactId>
<dependencies>
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-starter-client</artifactId>
        <version>2.2.1</version>
    </dependency>
</dependencies>

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 版本还是很美观大气上档次的,并且监控告警功能齐全,小微服务必备神器。

参考

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
JAVA開發(fā)工程師
手記
粉絲
1.7萬
獲贊與收藏
2438

關(guān)注作者,訂閱最新文章

閱讀免費(fèi)教程

  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消