Eureka不同网段内的ip访问配置

application.yml 配置

spring:
  application:
    name: xx-xxx-xxxx  #微服务名称
    
eureka:
  instance:
    hostname: svc-xxx-server
    ip-address: 192.168.111.111  #当前微服务外网的ip地址
    non-secure-port: 19999  #对外暴露的端口
    prefer-ip-address: true #有限ip访问
  client:
    service-url:
      defaultZone: ${REGISTRY_DEFAULT_ZONE:http://monitor-eureka/eureka/}  #eureka服务地址

FeignClient配置

import java.util.List;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(name = "XX-XXX-XXXX") // 微服务名称
public interface XxxService {

    @PostMapping("/ok")
    public void ok(@RequestParam String xx) throws Exception;
    
   // consumes="application/json" 配置-请求参数为json
    @PostMapping(value="/xxx",consumes="application/json")
    public Boolean xxx(@RequestBody List<xxxxxx> list) throws Exception;
}
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐