java version of spring cloud + spring boot social e-commerce platform - Create a "service provider"

Let's create a client to provide services, and to register their service registry. In this paper we introduce the registration and discovery service, so we might as well try to provide prescription provides an interface to get all of the current service information in the service.

Social e-commerce platform source code, please add penguin beg: three five San Lu wantonly II qi II five Jiu

First, create a basic Spring Boot application. Designated eureka-client, in pom.xml, add the following configuration:

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</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>

Secondly, to achieve / dc request processing interface through DiscoveryClient object instance print out the content of the service in the log.

@RestController
public class DcController {
@Autowired
DiscoveryClient discoveryClient;
@GetMapping("/dc")
public String dc() {
String services = "Services: " + discoveryClient.getServices();
System.out.println(services);
return services;
}
}

Finally, in the main application class by adding @EnableDiscoveryClient comment, the comment can be activated Eureka in DiscoveryClient achieved, so as to achieve the Controller output for service information.

@EnableDiscoveryClient
@SpringBootApplication
public class Application {
public static void main(String[] args) {
new SpringApplicationBuilder(
ComputeServiceApplication.class)
.web(true).run(args);
}
}

After we completed the implementation of services, and then continue to application.properties do some configuration work, as follows:

spring.application.name=eureka-client
server.port=2001
eureka.client.serviceUrl.defaultZone=http://localhost:1001/eureka/

By spring.application.name property, we can specify the name of the micro-services follow only need to use this name when calling on it to access the service. Configure Content eureka.client.serviceUrl.defaultZone property corresponds to the service registry, specify the location of a service registry. In order to test the machine and to distinguish the service provider service registry, a different set of attributes server.port port.

 

Of course, we can also gain direct access / dc interfaces eureka-client services provided by the current list of services

Services: [eureka-client]

Which, eureka-client in brackets is the interface to achieve eureka acquired in the service list of all DiscoveryClient by Spring Cloud defined. Since the Spring Cloud found that this layer of abstraction done a very good service, so, for the above program, we can seamlessly switch from the service management system eureka service to the area of governance system consul.
From now on, I will be here to build process and the essence of the recent development of micro-services cloud architecture springcloud record, have a friend help more interested in spring cloud development framework, I hope to help more good scholars. We come together to explore the process of spring cloud architecture to build and how to apply enterprise projects.
spring cloud b2b2c e-commerce social platform source code, please add penguin beg: three five San Lu wantonly II qi II five Jiu

 

Guess you like

Origin www.cnblogs.com/itcode-code/p/11198751.html