标签:状态 conf 同步 tps 服务 均衡器 work 创建 查看
创建一个基础的Spring Boot工程,并在pom.xml
中引入需要的依赖内容:
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.0.M2</version> <relativePath/> <!-- lookup parent from repository --> </parent> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class, args);
}
}
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka
#表示是否注册自身到eureka服务器,因为当前这个应用就是eureka服务器,没必要注册自身,所以这里是false
register-with-eureka: false
server:
enable-self-preservation: false
spring:
application:
name: eureka
#server:
# port: 8761
因为没有任何服务注册在上面,所以没有发现任何服务。
Demo地址:SpringCloudEurekaServer
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; @SpringBootApplication @EnableDiscoveryClient public class EurekaClientApplication { public static void main(String[] args) { SpringApplication.run(EurekaClientApplication.class, args); } }
将应用命名为test,并把服务注册到:
http://127.0.0.1:8761/eureka/
spring: application: name: test eureka: client: service-url: defaultZone: http://127.0.0.1:8761/eureka/
要保证服务提供中心保持运行状态才能注册上去
Demo地址:SpringCloudEurekaClinet
SpringCloud构建微服务 | 服务注册与发现(一)提供Demo
标签:状态 conf 同步 tps 服务 均衡器 work 创建 查看
原文地址:https://www.cnblogs.com/wdnnccey/p/10730225.html