eureka 搭建服务注册中心(本地)
1.在服务启动类中添加注解:
@EnableEurekaServer
@SpringBootApplication
public class ButterflyApplication {
public static void main(String[] args) {
SpringApplication.run(ButterflyApplication.class, args);
}
}
2. @EnableEurekaServer可能不识别 是因为boot与cloud版本不兼容
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</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>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
3.application.properties配置如下
#设置tomcat服务端口号
server.port=9990
#设置服务名称
spring.application.name=eureka-service
eureka.instance.hostname=localhost
#注册中心不需要注册自己
eureka.client.register-with-eureka=false
#注册中心不需要去发现服务
eureka.client.fetch-registry=false
#设置服务注册中心的URL
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka
参与文章:https://www.cnblogs.com/sam-uncle/p/8954401.html