需求
本地联调的时候,不想把本服务注册到开发环境的nacos中,但是又想用到开发环境的其他服务,又不想影响到开发环境的使用(因为服务注册上去,默认就自动负载均衡)。
解决方案
利用配置的方式指定具体的ip
spring:cloud:loadbalancer:retry:enabled: falseopenfeign:okhttp:enabled: trueclient:config:uaa-service:url: http://172.18.41.51:17001xxl-job-service:url: http://172.18.41.51:17002oss-service:url: http://172.18.41.51:17003sequence-service:url: http://172.18.41.51:17004security-service:url: http://172.18.41.51:17005system-service:url: http://172.18.41.51:17006data-cache-service:url: http://172.18.41.51:17007runtime-service:url: http://localhost:7003api-service:url: http://172.18.41.50:17001gateway-mq-service:url: http://172.18.41.50:17002xxljob-executor-service:url: http://172.18.41.50:17003gateway-service:url: http://172.18.41.50:17004console-service:url: http://172.18.41.50:17005
根据上面的配置,除了runtime-service是跳转到本地,其他的都指定到开发环境的机器,这样子就可以实现了。但是需要注意的是 FeginClient的注解 @FeignClient url 和path必须不能配置,否则会失效。