创建服务器,导入依赖
spring-boot-starter-parent和
spring-boot-starter-web和
spring-cloud-starter-eureka-server
在加入
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
配置application.yml`server:
port: 8761
eureka:
client:
register-with-eureka: false #表示是否将自身项目 注册为一个服务 否
fetch-registry: false #是否从其他服务器注册服务 发现 服务
service-url:
defaultZone: http://localhost:8761/eureka/ #表示从这个地址可以注册 获取微服务 `
main如下`@SpringBootApplication
@EnableEurekaServer
public class SpringBootPower {
public static void main(String[] args) {
SpringApplication.run(SpringBootPower.class, args);
}
}`
创建客户端
将服务器中的spring-cloud-starter-eureka-server依赖改为spring-cloud-starter-eureka
<dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
需要加入score
application.yml中加入`spring:
application:
name: Person
---
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
instance:
prefer-ip-address: true #表示当前ip地址注册到服务器 不写的话 默认注册的是计算机用户名 `