SpringCloud之搭建Eureka-Admin
阿新 • • 發佈:2018-12-29
雖然說在eureka的地址可以看到已經註冊到此服務,但有時候需要看到此服務的詳情,如:服務所在的環境詳情、記憶體情況、執行緒情況等,都無法看到,此時需要用到eureka-admin。
1.maven依賴
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.xichuan.dev</groupId> <artifactId>xichuan-eureka-admin</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>xichuan-eureka-admin</name> <description>eureka manage</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.6.RELEASE</version> <relativePath></relativePath> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</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> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> <version>1.3.2.RELEASE</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
2.application.yml配置
server: port: 2002 spring: application: #註冊到eureka的名稱 name: admin-server boot: admin: routes: endpoints: env,metrics,trace,dump,jolokia,info,configprops,trace,logfile,refresh,flyway,liquibase,heapdump,hystrix.stream #註冊到eureka eureka: client: serviceUrl: defaultZone: http://localhost:2001/eureka/ management.security.enabled: false
3.啟動類添加註解
import de.codecentric.boot.admin.config.EnableAdminServer; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; @SpringBootApplication @EnableAdminServer /**eureka-admin服務*/ @EnableDiscoveryClient /**註冊到eureka*/ public class XichuanEurekaAdminApplication { public static void main(String[] args) { SpringApplication.run(XichuanEurekaAdminApplication.class, args); } }
直接執行,後可以看到eureka註冊已經註冊了eureka-admin
訪問http://localhost:2002/,就可以使用eureka-admin了