我一直在尝试使用 Spring Cloud 和 Eureka 创建微服务。
现在我有一个服务器可以接收 2 个微服务:ACCOUNTS-SERVICE 和 WEB-SERVICE
[nio-1111-exec-2] c.n.e.registry.AbstractInstanceRegistry : Registered instance ACCOUNTS-SERVICE/192.168.0.13:accounts-service:2222 with status UP (replication=false)
[nio-1111-exec-4] c.n.e.registry.AbstractInstanceRegistry : Registered instance WEB-SERVICE/192.168.0.13:web-service:3333 with status UP (replication=false)
Run Code Online (Sandbox Code Playgroud)
这是我的网络服务:
package eu.epitech.jug.services.web;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
/**
* Created by sadzeih on 12/9/16.
*/
@SpringBootApplication
@EnableDiscoveryClient
@ComponentScan(useDefaultFilters=false)
public class WebServer {
public static void main(String[] args) {
// Will configure using web-server.yml
System.setProperty("spring.config.name", "web-server");
SpringApplication.run(WebServer.class, args); …Run Code Online (Sandbox Code Playgroud)