一、軟件版本列表:
1者铜、springcloud?版本?Hoxton.M3
<dependencyManagement>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Hoxton.M3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
2决摧、spring-boot-admin-server?版本 2.2.1
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
<version>2.2.1</version>
</dependency>
3、spring-boot-admin-starter-client?版本2.2.1
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.2.1</version>
</dependency>
二次乓、spring-boot-admin?服務(wù)器端配置
1颓鲜、創(chuàng)建springboot工程?web-monitor作為服務(wù)器端監(jiān)控程序
需要添加maven依賴
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>2.2.1</version>
</dependency>
2、創(chuàng)建boot啟動(dòng)類并添加注解(@EnableAdminServer)設(shè)置端口為8003
@SpringBootApplication
@ComponentScan(value ="com.ttsx")
@EnableAdminServer
public class WebMonitorApplication {
public static void main(String[] args) {SpringApplication.run(WebMonitorApplication.class, args);}
}
這里只給出springbootadmin相關(guān)代碼陕贮,關(guān)于eureka等相關(guān)配置這里不做描述堕油。?
二、spring-boot-admin客戶端程序
1肮之、創(chuàng)建boot程序并添加以下依賴掉缺。
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.2.1</version>
</dependency>
2、修改application.yml配置文件
spring:
????boot:
????????admin:
????????????client:
? ? ? ? ? ? ? ? #這里要指定到web-monitor服務(wù)器的IP和端口上
????????????????url:"http://localhost:8003"
management:
????????endpoints:
????????????web:
????????????????exposure:
????????????????????include:"*"
三戈擒、啟動(dòng)服務(wù):訪問(wèn)http://localhost:8003?可以看到下面的頁(yè)面
四眶明、出于安全考慮可以在客戶端引入
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
然后創(chuàng)建下面的類來(lái)安全驗(yàn)證
@Configuration
public class SecurityPermitAllConfigextends WebSecurityConfigurerAdapter {
@Override
? ? protected void configure(HttpSecurity http)throws Exception {
????http.authorizeRequests().anyRequest().permitAll()
.and().csrf().disable();
}
}