内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

SpringBootAdmin排坑指南是什么

Spring Boot Admin排坑指南是什么,針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

創(chuàng)新互聯(lián)從2013年創(chuàng)立,是專業(yè)互聯(lián)網(wǎng)技術服務公司,擁有項目成都網(wǎng)站設計、成都網(wǎng)站建設、外貿網(wǎng)站建設網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元賈汪做網(wǎng)站,已為上家服務,為賈汪各地企業(yè)和個人服務,聯(lián)系電話:13518219792

服務直接注冊失敗

常見的注冊失敗問題可以分為以下兩種

  • Spring Boot Admin服務端與客戶端不在同一臺服務器

  • 提示安全校驗不通過

第一種問題的解決辦法:

必須在客戶端配置boot.admin.client.instance.service-url屬性,讓Spring Boot Admin服務端可以通過網(wǎng)絡獲取客戶端的數(shù)據(jù)(否則默認會通過主機名去獲?。?/p>

  boot:
    admin:
      client:
        url: ${your spring boot admin url}
        username: ${your spring boot admin username}
        password: ${your spring boot admin password}
        instance:
          prefer-ip: true
          service-url: ${your spring boot client url}

第二種問題的解決辦法:

首先,安全檢驗問題,其實就是現(xiàn)在服務端配置賬號密碼,然后客戶端在注冊的時候提供賬號密碼進行登錄來完成校驗

這個過程的實現(xiàn),作為Spring全家桶項目,推薦使用Spring Security來解決,所以如果出現(xiàn)校驗失敗,那多半是Spring Security的配置出現(xiàn)問題

接下來介紹如何分別配置服務端與客戶端來處理這個問題

服務端配置

通過maven加載Spring Security依賴

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

設置服務端的用戶名和密碼(客戶端來注冊時使用此賬號密碼進行登錄)

spring:
  security:
    user:
      name: liumapp
      password: superliumapp

編寫Spring Security配置類

import de.codecentric.boot.admin.server.config.AdminServerProperties;
import org.springframework.context.annotation.Configuration;
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;

/**
 * file SecuritySecureConfig.java
 * author liumapp
 * github https://github.com/liumapp
 * email liumapp.com@gmail.com
 * homepage http://www.liumapp.com
 * date 2018/11/29
 */
@Configuration
public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
    private final String adminContextPath;

    public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
        this.adminContextPath = adminServerProperties.getContextPath();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // @formatter:off
        SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
        successHandler.setTargetUrlParameter("redirectTo");
        successHandler.setDefaultTargetUrl(adminContextPath + "/");

        http.authorizeRequests()
                .antMatchers(adminContextPath + "/assets/**").permitAll()
                .antMatchers(adminContextPath + "/login").permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()
                .logout().logoutUrl(adminContextPath + "/logout").and()
                .httpBasic().and()
                .csrf()
                .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
                .ignoringAntMatchers(
                        adminContextPath + "/instances",
                        adminContextPath + "/actuator/**"
                );
        // @formatter:on
    }
}

上面這段代碼,需要大家注意的就一個AdminServerProperties類,通過瀏覽它的部分源代碼:

@ConfigurationProperties("spring.boot.admin")
public class AdminServerProperties {
    /**
     * The context-path prefixes the path where the Admin Servers statics assets and api should be
     * served. Relative to the Dispatcher-Servlet.
     */
    private String contextPath = "";
    
    /**
     * The metadata keys which should be sanitized when serializing to json
     */
    private String[] metadataKeysToSanitize = new String[]{".*password$", ".*secret$", ".*key$", ".*$token$", ".*credentials.*", ".*vcap_services$"};

    /**
     * For Spring Boot 2.x applications the endpoints should be discovered automatically using the actuator links.
     * For Spring Boot 1.x applications SBA probes for the specified endpoints using an OPTIONS request.
     * If the path differs from the id you can specify this as id:path (e.g. health:ping).
     */
    private String[] probedEndpoints = {"health", "env", "metrics", "httptrace:trace", "httptrace", "threaddump:dump", "threaddump", "jolokia", "info", "logfile", "refresh", "flyway", "liquibase", "heapdump", "loggers", "auditevents", "mappings", "scheduledtasks", "configprops", "caches", "beans"};
    
    //以下省略...
    
}

可以發(fā)現(xiàn)AdminServerProperties定義了Spring Boot Admin的配置屬性,登錄自然也是其中之一,所以我們在編寫Spring Security配置類的時候,務必要引入AdminServerProperties

到這里,Spring Boot Admin服務端對于Spring Security的配置便結束了,接下來讓我們開始客戶端的Security配置

客戶端配置

首先對于客戶端,我們除了Spring Boot Admin Client依賴外,還需要額外引入 Spring Security依賴:

<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
    <version>2.0.2</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

在此基礎上通過編寫客戶端application.yml配置文件來設置賬號密碼

spring:
  boot:
    admin:
      client:
        url: ${your sba server url}
        username: ${your sba username}
        password: ${your sba password}
        instance:
          service-base-url: ${your client url}

接下來對Client端的Spring Security做配置,允許Server端讀取actuator暴露的數(shù)據(jù)

添加一個配置類:

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
public class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().permitAll()
                .and().csrf().disable();
    }
}

到此,因為安全驗證而不能注冊成功的問題便可以解決

注冊成功但無法顯示日志

這個問題產(chǎn)生原因有兩種

  • 客戶端日志沒有以文件形式存儲下來

  • 客戶端容器化部署后,日志文件沒有映射到宿主機磁盤上

針對第一種情況,解決辦法比較簡單,將系統(tǒng)產(chǎn)生的日志以文件形式保存即可:

logging:
  file: ./log/client.log
  pattern:
    file: "%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID}){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx"

第二種情況較為復雜,首先要分清除是用什么工具來部署容器的,但一般而言直接通過文件映射即可

這里以docker為例,在docker內通過設置volumes來映射日志文件

volumes:
  - ./log:/client/log/

注冊成功但信息顯示不全

偶爾也會遇到這種情況:Spring Boot Admin客戶端注冊服務端是成功的,但是統(tǒng)計頁面顯示的數(shù)據(jù)過少(可能只有日志這一欄)

造成這種問題的原因在于:我們沒有開放客戶端的actuator接口地址給服務端訪問

那么解決辦法也很簡單,允許服務端訪問actuator即可

首先我們需要確保項目有actuator依賴(一般來說,spring-boot-admin-starter-client本身就包含這個依賴,所以不需要額外引入):

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

然后打開actuator的端口,在client端的配置文件中增加以下內容:

management:
  endpoints:
    web:
      exposure:
        include: "*"

同時考慮到client與server域名存在不一樣的情況,順便把跨域也解決掉,增加跨域配置類:

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author liumapp
 * @file CorsConfig.java
 * @email liumapp.com@gmail.com
 * @homepage http://www.liumapp.com
 * @date 2018/8/11
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {
   
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowCredentials(true)
                .allowedHeaders("*")
                .allowedOrigins("*")
                .allowedMethods("*");

    }
}

關于Spring Boot Admin排坑指南是什么問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關知識。

分享題目:SpringBootAdmin排坑指南是什么
網(wǎng)址分享:http://www.rwnh.cn/article28/jdccjp.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設、域名注冊品牌網(wǎng)站建設、手機網(wǎng)站建設、網(wǎng)站收錄、做網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設
天峻县| 北京市| 景洪市| 治多县| 张掖市| 忻州市| 乐山市| 于田县| 遂川县| 新沂市| 寿光市| 黄浦区| 尼勒克县| 石河子市| 夏津县| 波密县| 平邑县| 雅安市| 和顺县| 体育| 婺源县| 五大连池市| 舒城县| 林周县| 桐乡市| 定安县| 龙口市| 胶州市| 泸溪县| 二连浩特市| 湟中县| 河东区| 绥宁县| 通许县| 宁陵县| 榆树市| 揭西县| 禄丰县| 射阳县| 原阳县| 米脂县|