1、在客户端maven项目中添加eureka客户端依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency>
2、在工程application.yml文件中添加注册配置
#客户端注册
eureka:
client:
register-with-eureka: true #是否向注册中心注册自己 默认为true
fetch-registry: true #是否需要检索服务 默认为true
service-url:
defaultZone: http://eternity:1234qwer@localhost:4405/eureka/
可以简化为:
#客户端注册
eureka:
client:
service-url:
defaultZone: http://eternity:1234qwer@localhost:4405/eureka/
defaultZone配置的为Eureka的注册地址:
如果Eureka没有使用Security的安全用户认证,则配置路径为:
http://localhost:4405/eureka/ 即:http://server.host:server.port/eureka/
如果Eureka使用安全用户认证,需要加上账号密码。
http://eternity:1234qwer@localhost:4405/eureka/ 即:http://username:password@server.host:server.port/eureka/
3、配置成功后,启动注册中心、启动客户端,查看是否注册成功。
在应用里面显示配置成功。这就说明服务已经注册完成了。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/260258.html