foreword
This article mainly introduces how the role of service provider is linked with the registry.
text
The first step is to rely on
Dependencies required by the server in Maven's .pom file:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.3.RELEASE</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>
The second step is to configure
Define a configuration file, either named application.yml or application.properties.
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8762/eureka/
server:
port:
9999
spring:
application:
name: provider
The third step, service class
Build a service provider class, take rest as an example:
package com.silence.spring.cloud.provider;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ProviderController {
@RequestMapping("/getInfo")
public String getInfo() {
return "provider";
}
}
The fourth step, start
Build the startup class:
package com.silence.spring.cloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication
@EnableEurekaClient
public class ProviderApplication {
public static void main(String[] args) {
SpringApplication.run(ProviderApplication.class, args);
}
}
verify
Similarly, check the registration center http://localhost:8762/ , if the following figure appears, it proves that the service registration is successful.