之前有服务使用的springboot作为后台,现在搭建了springcloud,想把springboot加入里面
1、添加依赖
依赖一定要添加正确,否则会导致服务发现不了,甚至报错情况
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
2.2.2.RELEASE
2、application启动程序添加注解
给application启动程序添加注解 @EnableEurekaClient
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication
@EnableEurekaClient
3、修改配置文件
在application.properties添加服务注册信息
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.serviceUrl.defaultZone=http://localhost:10081/eureka/
spring.application.name=newStar
eureka.instance.status-page-url=http://localhost:5555/index
eureka.instance.hostname=localhost
4、服务启动
重启服务,成功后查看eureka页面是否已经添加服务