Spring Cloud微服务架构(二)服务发现

不念不忘少年蓝@ 2022-03-17 03:28 280阅读 0赞

一、服务注册好了之后,再创建一个服务提供的客户端。新建一个Spring Boot工程。在pom.xml文件中添加以下依赖:

  1. <dependency>
  2. <groupId>org.springframework.cloud</groupId>
  3. <artifactId>spring-cloud-starter-eureka</artifactId>
  4. </dependency>
  5. <dependencyManagement>
  6. <dependencies>
  7. <dependency>
  8. <groupId>org.springframework.cloud</groupId>
  9. <artifactId>spring-cloud-dependencies</artifactId>
  10. <version>Dalston.SR3</version>
  11. <type>pom</type>
  12. <scope>import</scope>
  13. </dependency>
  14. </dependencies>
  15. </dependencyManagement>

二、在启动类上加@EnableDiscoveryClient注解

  1. @EnableDiscoveryClient //启动发现服务能力
  2. @SpringBootApplication
  3. public class Springtest2Application {
  4. public static void main(String[] args) {
  5. new SpringApplicationBuilder(Springtest2Application.class).web(true).run(args);
  6. }

}

三、然后对application.properties文件进行以下配置:

  1. spring.application.name=springtest2
  2. server.port=2222
  3. eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/

四、运行上个工程的启动类,再运行本工程的启动类,访问http://localhost:1111/你将会看到以下页面。注意红色方框,表明已经有服务注册了。

在这里插入图片描述

欢迎大家关注我的微信公众号!

在这里插入图片描述

请打开支付宝扫一扫,有红包领哦!

在这里插入图片描述
感谢阅读,希望对你有所帮助。

发表评论

表情:
评论列表 (有 0 条评论,280人围观)

还没有评论,来说两句吧...

相关阅读