Eureak服务端
在启动类上添加注解,详情如下
@SpringBootApplication
@EnableEurekaServer //服务端的启动类,可以接受别人注册进来
public class EureakServer_7001 {
public static void main(String[] args) {
SpringApplication.run(EureakServer_7001.class,args);
}
}
编写配置文件
server:
port: 7001
#Eureka配置
eureka:
instance:
hostname: eureka7001.com #Eureka服务端的实例名称
client:
register-with-eureka: false #表示是否向eureak注册中心注册自己
fetch-registry: false #fetch-registry如果为false,则表示自己为注册中心
service-url: # 监控页面
defaultZone: http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/ # Eureka集群
Eureak客户端
在启动类上添加注解,详情如下
@SpringBootApplication
@EnableEurekaClient //将服务注册到注册中心
public class DeptProvidet_8802 {
public static void main(String[] args) {
SpringApplication.run(DeptProvidet_8802.class,args);
}
}
Controller层
@RestController
public class DeptController {
@Autowired
DeptService deptService;
@Autowired
private DiscoveryClient client;
@PostMapping("/adddept")
public boolean HelloDept(Dept dept){
return<