This tutorial is divided into 3 stages.
Imported project structure looks like below.
Previous Next Homea. Setting Discovery Server
b. Setting Application Service
c. Setting Application Client
In this post, I am going to explain how to set up discovery server.
Setting Discovery Server
Step 1: Go to ‘https://start.spring.io/’ and create skelton project.
Give the Group name as ‘com.sample.app’, Artifact as ‘DiscoveryServer’ and add below dependencies.
a. Eureka Server
b. Spring Boot DevTools
c. Spring Boot Actuator
Click on the button ‘Generate the project’.
Save the project.
Step 2: Extract the downloaded zip file.
Step 3: Import the downloaded project to Eclipse.
Open Eclipse.
File -> Import.
Search for Maven.
Select ‘Existing Maven Projects’. Click on Next button.
Browse the extracted application location, click on Finish button.
Step 2: Add ‘@EnableEurekaServer’ annotation to DiscoveryServerApplication.java file.
DiscoveryServerApplication.java
package com.sample.app.DiscoveryServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class DiscoveryServerApplication {
public static void main(String[] args) {
SpringApplication.run(DiscoveryServerApplication.class, args);
}
}
Step 3: Update src/main/resources/application.properties file.
application.properties
spring.application.name=discovery-server
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
server.port=9090
spring.application.name=discovery-server
It is used as the application name when registering with a service registry such as eureka.
eureka.client.register-with-eureka=false
Since we are running this server in standalone mode, we are telling Eureka client to not to register itself upon start up.
eureka.client.fetch-registry=false
It will tell not to search for other registry nodes to connect to, as there are none.
server.port=9090
Run the application on port 9090.
Run DiscoveryServerApplication.java.
Open the url ‘http://localhost:9090/’ in browser, you can see below screen.
Related Articles
This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here