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);
	}

}

访问:http://localhost:8189

 

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);
	}
	
}

这样就可以用了:

 详细使用方式: https://blog.csdn.net/hubo_88/article/details/80671192

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐