Create a basic spring boot project, named eureka-server
, and pom.xml
introduce the required dependencies in:
12345678910111213141516171819202122232425 |
<parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>1.5.4.release</version> <relativepath/> </parent> <dependencies> <dependency> <groupid>org.springframework.cloud</groupid> <artifactid>spring-cloud-starter-eureka-server</artifactid> </dependency> </dependencies> <dependencymanagement> <dependencies> <dependency> <groupid>org.springframework.cloud</groupid> <artifactid>spring-cloud-dependencies</artifactid> <version>dalston.sr1</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencymanagement> |
@EnableEurekaServer
Start a service registry with annotations to provide conversations for other apps. This step is very simple, just add this annotation to a normal spring boot application to enable this feature, such as the following example:
123456789 |
@EnableEurekaServer @SpringBootApplication public class application { public static void main(string[] args) { new Springapplicationbuilder (Application.class). Web (True). Run (args);} |
By default, the service registry will also try to register itself as a client, so we need to disable its client registration behavior by simply application.properties
adding the following information to the configuration file:
123456 |
spring.application.name=eureka-serverserver.port=1001 eureka.instance.hostname= Localhosteureka.client.register-with-eureka=falseeureka.client.fetch-registry=false |
To differentiate the service from subsequent registrations, the port for the service registry is set to 1001 via the Server.port property. After you start the project, you can see the following page, where no services have been found.
From now on, I will record the process and the essence of the recently developed Springcloud micro-service cloud architecture, and help more friends who are interested in developing the Spring cloud framework, hoping to help more good scholars. Let's explore how the Spring cloud architecture is built and how it can be used in enterprise projects. Source Source
Spring Cloud builds a microservices architecture-Create a service registration center