如何在春云Netflix eureka上注册spring boot microservices?(How to register spring boot microservices on spring

编程入门 行业动态 更新时间:2024-10-23 03:23:39
如何在春云Netflix eureka上注册spring boot microservices?(How to register spring boot microservices on spring cloud Netflix eureka?)

我们计划使用Spring云Netflix oss组件。 所以我正在做一个小样本项目。 我开发了2个spring的微服务,这些服务在http:// localhost:9000 / microsvc-one http:// localhost:9001 / microsvc-two上运行良好

还写了一个样例spring cloud etflix eureka maven项目,它在http:// localhost:8761上运行良好

我在Spring引导微服务主类中使用了注释@EurekaDiscoveryClient和@SpringBootApplication

我使用了注释@EnableEurekaServer和@SpringBootApplication

现在,我在使用尤里卡服务器注册这些服务时遇到了问题。 我提到了一些样品。 我不了解那些。 我在microsvc-one和microsvc-two的application.yml文件以及尤里卡服务器的application.yml文件中做了一些更改。 但它仍然显示空虚。

所有变更都需要或丢失或正确的配置,以便我的服务在尤里卡注册。

我还有其他问题,比如我是否需要创建一个单独的项目,其中有@EnableConfigServer和@SpringBootApplication注释,而不是上述2个微服务和尤里卡服务器项目模块,以在尤里卡注册服务。 我在大多数例子中看到了这些。

如果是的话,我们如何链接所有这些?

We were planning to use spring cloud Netflix oss components. So I was doing a small sample project. I developed 2 spring microservices and those services runs well on http://localhost:9000/microsvc-one http://localhost:9001/microsvc-two

And also wrote a sample spring cloud etflix eureka maven project which runs well on http://localhost:8761

I used annotations @EurekaDiscoveryClient and @SpringBootApplication on both the spring boot microservices main class

I used annotation @EnableEurekaServer and @SpringBootApplication

Now I am facing a problem in registering those services in eureka server. I referred some samples. I am not understanding those. I did some changes in application.yml files of microsvc-one and microsvc-two and also application.yml file of eureka server. But still it shows empty.

What all changes are required or missing or correct configuration to be done so that my services are being registered on eureka.

I also have other question like do i need to create a separate project which has @EnableConfigServer and @SpringBootApplication Annotations other than the above 2 microservices and eureka server project module to register the services on eureka. I see those in most of the examples.

If yes..how do we link between all these?

最满意答案

如果您使用springBoot应用程序,您将需要注释@SpringBootApplication,这就是您看到的项目中存在该注释的原因。 @EnableConfigServer是当你使用spring-cloud配置服务器的时候,它用于外部化配置属性,但是因为你在项目中有application.yml,所以你也不需要这样做。

我认为你有一个适用于微服务和Eureka服务器的spring启动应用程序。 你需要用尤里卡主类注解

@SpringBootApplication @EnableEurekaServer @EnableDiscoveryClient public class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); } }

此外,你需要用微软服务的主要类来注释你..

@SpringBootApplication @EnableDiscoveryClient public class MicroApplication { public static void main(String[] args) { SpringApplication.run(MicroApplication.class, args); } }

既然你没有你在这里的问题application.yml文件是你需要的。

在微服务的application.yml中需要下面的配置。

eureka: client: serviceUrl: defaultZone: ${eurekaurl:http://localhost:8761/eureka/}

在尤里卡服务器application.yml文件中我有这个在我的。 你可能需要根据你想要的来调整它。

info: component: Registry Server server: port: ${port:8761} eureka: client: registerWithEureka: false fetchRegistry: false server: enable-self-preservation: false waitTimeInMsWhenSyncEmpty: 0 instance: hostname: localhost lease-expiration-duration-in-seconds: 15 lease-renewal-interval-in-seconds: 5

If you are using springBoot application you will need the annotaion @SpringBootApplication thats why that annotation is there on the project you are seeing. @EnableConfigServer is when you are using the spring-cloud config server it is used to externalize the configuration properties but since you have the application.yml inside the project so you donot need that either.

I am thinking you have a spring boot application for both Microservices and the Eureka server. You need to annotate the eureka main class with

@SpringBootApplication @EnableEurekaServer @EnableDiscoveryClient public class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); } }

Additionally you need annotate you microservice's main class with..

@SpringBootApplication @EnableDiscoveryClient public class MicroApplication { public static void main(String[] args) { SpringApplication.run(MicroApplication.class, args); } }

Since you donot have you application.yml file in the question here is what you need.

You need the below configuration in application.yml of the microservices.

eureka: client: serviceUrl: defaultZone: ${eurekaurl:http://localhost:8761/eureka/}

In the Eureka Server application.yml file I have this in mine. you might need to tweak it based on what you want.

info: component: Registry Server server: port: ${port:8761} eureka: client: registerWithEureka: false fetchRegistry: false server: enable-self-preservation: false waitTimeInMsWhenSyncEmpty: 0 instance: hostname: localhost lease-expiration-duration-in-seconds: 15 lease-renewal-interval-in-seconds: 5

更多推荐

本文发布于:2023-08-07 12:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464235.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   春云   eureka   Netflix   spring

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!