springboot不注册eureka

常规工程中,使用@EnableEurekaClien注解+yml配置,可以将自己注册到注册中心上去。

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

其实,还可以使用@EnableFeignClients注解+yml配置,将自己注册到注册中心上去

但是!因为@EnableFeignClients是spring-cloud-openfeign-code的注解。

如果pom文件中不引入以下配置。

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

代码运行是正常的,但是不会注册到注册中心上。需要引入上面的这个配置,才可以注册到注册中心上去。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot可以很方便地集成Eureka,实现服务注册和发现。以下是集成步骤: 1. 添加Eureka依赖 在pom.xml文件中添加以下依赖: ``` <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> ``` 2. 配置Eureka Server 在Spring Boot应用的配置文件中添加以下配置: ``` server.port=8761 eureka.client.register-with-eureka=false eureka.client.fetch-registry=false ``` 其中,server.port指定Eureka Server的端口号,eureka.client.register-with-eurekaeureka.client.fetch-registry设置为false表示该应用不会向Eureka Server注册自己,也不会从Eureka Server获取服务列表。 3. 启动Eureka Server 在Spring Boot应用的启动类上添加@EnableEurekaServer注解,启动Eureka Server。 ``` @SpringBootApplication @EnableEurekaServer public class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); } } ``` 4. 配置Eureka Client 在Spring Boot应用的配置文件中添加以下配置: ``` server.port=808 spring.application.name=my-service eureka.client.service-url.defaultZone=http://localhost:8761/eureka/ ``` 其中,server.port指定应用的端口号,spring.application.name指定应用的名称,eureka.client.service-url.defaultZone指定Eureka Server的地址。 5. 启动Eureka Client 在Spring Boot应用的启动类上添加@EnableDiscoveryClient注解,启动Eureka Client。 ``` @SpringBootApplication @EnableDiscoveryClient public class MyServiceApplication { public static void main(String[] args) { SpringApplication.run(MyServiceApplication.class, args); } } ``` 6. 测试 启动Eureka Server和Eureka Client后,可以在Eureka Server的管理界面(http://localhost:8761/)上看到注册的服务。可以通过Eureka Client的应用名称访问该服务,例如:http://localhost:808/hello。 以上就是Spring Boot集成Eureka的步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值