利用 Spring Boot 可以快速開發客製化應用系統, 而這些由 Spring Boot 框架建立的應用系統則可以利用 Spring Boot Admin 來作統一的管理. 由這系統可以讓您知道 Application Server 的版本如: Java , Tomcat , session .... 等, 所以在管理這些服務系統架構中...監控管理是非常重要的一環

Server 端

1. 建立一個新的 Spring Starter Project : sbAdmin , 且只要選擇 Web 就好. 其它的相依套件如下:

buildscript {
	ext {
		springBootVersion = '2.1.1.RELEASE'
	}
	repositories {
		mavenCentral()
	}
	dependencies {
		classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
	}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.admin'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
	mavenCentral()
}


dependencies {
	implementation('org.springframework.boot:spring-boot-starter-web')
	compile('de.codecentric:spring-boot-admin-starter-server:2.1.1') // SpringBoot Admin
	testImplementation('org.springframework.boot:spring-boot-starter-test')
}

Server 端的 application.properties 設定啟動的 port: 8099


server.port=8099

Client 端

引入的相依套件

dependencies {
	compile('de.codecentric:spring-boot-admin-starter-client:2.1.1') // SpringBoot Admin Client
}

設定Spring Boot Admin 可以存取 Client 端的設定

    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity                
                .csrf().disable()
                .authorizeRequests()
                
                // 首頁
                .antMatchers("/home").permitAll()
                .antMatchers("/actuator/**").permitAll()                
                .anyRequest().authenticated()   // 除了以上的 URL 外, 都需要認證才可以訪問
                .and()
    			.formLogin()
    				.loginPage("/login")
    				//.failureHandler(authFailureHandler) // 使用 Spring 預設
    				.successForwardUrl("/auth/home")
    				.permitAll()
    				.and()
    	        .logout()
                    .permitAll();
    }

Client 端的 application.properties 設定


# =================================
# Spring Boot Admin Client
# http://codecentric.github.io/spring-boot-admin/2.1.1/
# ================================
spring.boot.admin.client.url=http://localhost:8099
management.endpoint.health.show-details=always
management.endpoints.enabled-by-default=true
management.endpoints.web.exposure.include=*

以上, 啟動後連結 http://localhost:8099 就可以了. 很快速吧.

官方的介紹

Application Servers List

>Spring Boot Admin

Dashboard with desktop notifications

undefined

arrow
arrow

    MIS 發表在 痞客邦 留言(0) 人氣()