1.创建一个模块Eureka_user_service_2000和一个Eureka_order_serice_3000的两个客服端(下面只有一个的,自己改一下就可以了)
在pom中
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
3.写入配置文件和主配置类
allication.yml中
eureka: client: serviceUrl: defaultZone: http://localhost:1000/eureka/ #注册中心地址 server: port: 2000 spring: application: name: user-server
主配置类
package cn.jiedada; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication @EnableEurekaClient public class Application { public static void main(String[] args) { new SpringApplicationBuilder(Application.class).web(true).run(args); } }
controller
package cn.jiedada; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class UuserController { @RequestMapping("/") public String home() { return "Hello world"; } }
必须要开启服务器端才能使用客户端页面成功如下