spring boot admin 實現對服務的監控
阿新 • • 發佈:2018-12-31
service端:
專案依賴:
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server</artifactId> <version>1.5.6</version> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui</artifactId> <version>1.5.6</version> </dependency> </dependencies>
配置檔案:
server:
port: 8000
spring:
application:
name: admin-server
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
client:
registryFetchIntervalSeconds: 5
serviceUrl:
defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/
management.security.enabled: false
啟動類:
@EnableEurekaClient
@SpringBootApplication
@EnableAdminServer
public class SilkRoadEruekaApplication {
public static void main(String[] args) {
SpringApplication.run(SilkRoadEruekaApplication.class, args);
}
}
client端:
依賴:
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> <version>1.5.7</version> </dependency> </dependencies>
啟動類:
啟動類不需要新增admin相關的註解
@EnableEurekaClient
@SpringBootApplication
public class SrDhTraApplication {
public static void main(String[] args) {
SpringApplication.run(SrDhTraApplication.class, args);
}
}
這樣就可以用了: