In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to configure the project structure in Spring cloud to implement Eureka services". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to configure the project structure to implement Eureka services in Spring cloud.
Parent project management
First of all, before creating a delivery system, let's take a look at our engineering structure:
Mscx-ad-sponsor is our advertising system. With the above structure, we need to first create a Parent Project mscx-ad
To write the pom of the parent project to manage our unified dependency information.
4.0.0 pom mscx-ad-discovery mscx-ad-zuul mscx-ad-gateway mscx-ad-discovery-nacos mscx-ad-common mscx-ad-db mscx-ad-sponsor mscx-ad-search mscx-ad-feign-sdk org.springframework.boot spring-boot-starter-parent 2.1.5.RELEASE Com.sxzhongf mscx-ad 1.0-SNAPSHOT distributed Advertising system 1.8 Greenwich.SR2 org.projectlombok lombok org.springframework.boot spring-boot-starter-test test based on Spring Cloud Alibaba Org.springframework.boot spring-boot-starter-actuator org.springframework.cloud spring-cloud-dependencies ${spring-cloud.version} pom import Spring-milestones Spring Milestones https://repo.spring.io/milestone false alibaba-milestones ali Milestones http://maven.aliyun.com/nexus/content/groups/public/ False org.springframework.boot spring-boot-maven-plugin Service Discovery Eureka
Eureka Server (providing registration and discovery of services)
Eureka Client
Service provider (the service provider registers itself with server so that Eureka Server can save provider's metadata so that other service consumers can find the current service)
Service Consumer (service consumer who consumes services by obtaining a list of registered services from Eureka Server)
Create project mscx-ad-discovery, then use the SpringBoot project trilogy (add dependency, annotate, change configuration)
Write POM, focusing on relying on spring-cloud-starter-eureka-server mscx-ad com.sxzhongf 1.0-SNAPSHOT.. / pom.xml 4.0.0 jar com.sxzhongf mscx-ad-discovery 1.0-SNAPSHOT service discovery components to be implemented using eureka first Later, nacos will be used to replace org.springframework.cloud spring-cloud-starter-eureka-server 1.2.7.RELEASE org.springframework.boot spring-boot-maven-plugin and add comments (@ EnableEurekaServer) @ SpringBootApplication@EnableEurekaServerpublic class DiscoveryApplication {public static void main (String [] args) {SpringApplication.run (DiscoveryApplication.class) Args) }} change the configuration
Single point
Spring: application: name: ad-discovery-serverserver: port: 8888eureka: instance: hostname: localhost # stand-alone client: fetch-registry: false # whether to obtain registration information from eureka server register-with-eureka: false # register yourself to eureka service-url: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
Cluster
When testing, you need to modify the hosts file
ZhangpandeMacBook-Pro:etc zhangpan$ cat hosts##...##127.0.0.1 localhost127.0.0.1 server1127.0.0.1 server2127.0.0.1 server3::1 localhost
Then modify the application.yml
Spring: application: name: ad-discovery profiles: server1server: port: 7777eureka: instance: hostname: server1 prefer-ip-address: false client: service-url: defaultZone: http://server2:8888/eureka/, Http://server3:9999/eureka/---spring: application: name: ad-discovery profiles: server2server: port: 8888eureka: instance: hostname: server2 prefer-ip-address: false client: service-url: defaultZone: http://server1:7777/eureka/, Http://server3:9999/eureka/---spring: application: name: ad-discovery profiles: server3server: port: 9999eureka: instance: hostname: server3 prefer-ip-address: false client: service-url: defaultZone: http://server2:8888/eureka/,http://server1:7777/eureka/
Start the cluster test:
Configure to launch profile / java-jar mscx-ad-discovery.jar-- spring.profiles.active=server1
Effect display
At this point, I believe you have a deeper understanding of "how to configure the project structure to implement Eureka services in Spring cloud". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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: 0
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.