spring boot 搭建Eureka注册中心
1.新建spring boot 项目
file -> new spring starter project
点击next之后选择要引入的包
勾选 eurka server 然后点击finsh
application.properties配置
server.port=8786
eureka.instance.hostname=localhost
# 是否向注册中心注册自己(因为它就是注册中心,负载均衡时需要用到)
eureka.client.register-with-eureka=false
# 是否需要检索服务(检索服务是client端的事)
eureka.client.fetch-registry=false
# eureka服务器访问地址
eureka.client.service-url.defaultZone:http://${eureka.instance.hostname}:${server.port}/eureka/
在Application启动类上新增注解
然后启动spring boot就会 报错 无法启动嵌入式Tomcat
原因是我们在创建spring boot 项目中没有勾选 spring web satrter 导致的
解决方法 :
pom文件添加以下代码:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
重新启动 spring boot 问题就解决了
在浏览器输入 http://localhost:8786/
表示成功