Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Construction steps of SpringCloud Eureka

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "the steps of building SpringCloud Eureka". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn the steps of building SpringCloud Eureka.

What is 1.SpringCloud?

In the past, the server was like a hospital with only one doctor, and all patients had to be seen by this doctor. if the doctor felt too tired and died suddenly, the whole hospital would be paralyzed. After springcloud became popular, it was as if there were surgical and internal medicine rooms in the hospital, and there were a group of doctors in charge of each consultation room, so that no matter which doctor failed, it would not affect the operation of the whole hospital. Classify and decouple the many services in one or more servers, assign their similar functions to the same cluster, peel off the coupled functions, and put them on the server as micro-services by function, and this server provides only one service, or less service. Let a super-large service logic, decoupled into a small service, evenly distributed in their respective servers. This is springcloud.

What does 2.Eureka do?

Each clinic is a micro-service cluster, and they all provide the same function. The registry Eureka is equivalent to the membership table of each clinic.

Construction of 3.Eureka

Create a project in Idea: File-> New-> Project-> Empty Project-> Next

Click on the next step and we are done.

Create a Module file

Select quickstart and click next (this page may take a while to load)

Write the group name and file name casually, and finish it until the next step.

Configure the pom file

Org.springframework.boot spring-boot-starter-parent 1.5.7.RELEASE org.springframework.cloud spring-cloud-starter-netflix-eureka-server org.springframework.cloud spring-cloud-dependencies Edgware.SR5 pom import

And then began to guide the package. A long wait

Create a folder resources under main and set it as a resource folder

Create a new file under resources and name it appliaction.yml

Configure appliaction.yml

Server: port: 8700 # Port number at will # specify the registered address of the current eureka client, that is, the provider of the eureka service The registrant of the currently configured service eureka: client: service-url: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka register-with-eureka: false # itself does not register with eureka fetch-registry: false # disable the registration of client at startup instance: hostname: localhost# specifies the application name spring: application: name: eureka-server

Create a new file, EurekaServerAppliaction.java, under the buting folder, and write the following code.

@ SpringBootApplication@EnableEurekaServer / / serverpublic class EurekaServerApplication {public static void main (String [] args) {SpringApplication.run (EurekaServerApplication.class,args); System.out.println ("2333");}} currently using eureka

Right-click Debug to run, and after running successfully, type http://localhost:8700 if the following interface appears, our first step will be considered successful.

Next, it's time to configure the client, which provides the configuration of the role, and provides the service to register with the service registrar (that is, the server we just configured). As in the above steps, we create a new Module file, and we need to note that the above two selections are

After creating the file, let's configure the pom file to introduce the following dependencies

Org.springframework.boot spring-boot-starter-parent 1.5.7.RELEASE org.springframework.cloud spring-cloud-starter-netflix-eureka-client org.springframework.cloud spring-cloud-dependencies Edgware.SR5 pom import

Okay, actually change the server in dependency to client, and then we create the resources folder, create the application.yml file, and configure it like this.

Server: port: 8701 # provider # specifies the registered address of the current eureka client, eureka: client: service-url: defaultZone: http://${eureka.instance.hostname}:8700/eureka instance: hostname: localhost # current service name spring: application: name: eureka-servicepom.xml:

Because you are building a service provider, you also need to write the service class controller

@ RestController@RequestMapping ("/ Hello") public class Controller {@ RequestMapping ("/ World") public String helloWorld (String s) {System.out.println ("the value passed in is:" + s); the value passed in by return is: "+ s;}}

Enter the class and run this microservice

@ SpringBootApplication@EnableDiscoveryClient// represents itself as a service provider public class EurekaServiceApplication {public static void main (String [] args) {SpringApplication.run (EurekaServiceApplication.class,args);}}

Right-click Debug (of course, when you start this service, you need to open the server service, which is the first micro-service we wrote), wait for it to run successfully, and then go to the server page (the page we configured for the first time, not this one)

On the page, we can see that the service provider has been registered with the service registrant

Thank you for your reading, the above is the content of "the steps of building SpringCloud Eureka". After the study of this article, I believe you have a deeper understanding of the steps of building SpringCloud Eureka, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 298

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report