openfeign配置代理服务器

openfeign配置代理服务器第一步 配置文件允许覆盖 Beanspring main allow bean definition overriding true 第二步 配置 Beanpackagec ciih refine config importokhttp importorg springframew cloud commons httpclient DefaultOkHtt importorg springframew cloud

第一步:配置文件允许覆盖Bean

spring: main: allow-bean-definition-overriding: true

第二步:配置Bean

package com.ciih.refine.config; import okhttp3.*; import org.springframework.cloud.commons.httpclient.DefaultOkHttpClientFactory; import org.springframework.cloud.commons.httpclient.OkHttpClientFactory; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import java.io.IOException; import java.net.InetSocketAddress; import java.net.Proxy; @Configuration //配置openfein接口的文件件路径 @EnableFeignClients(basePackages = "com.ciih.refine.server") public class Config { @Bean public OkHttpClientFactory okHttpClientFactory(OkHttpClient.Builder builder) { return new ProxyOkHttpClientFactory(builder); } static class ProxyOkHttpClientFactory extends DefaultOkHttpClientFactory { public ProxyOkHttpClientFactory(OkHttpClient.Builder builder) { super(builder); //配置IP、端口 Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("190.168.1.1", 8080)); builder.proxy(proxy); builder.proxyAuthenticator(new Authenticator() { @Override public Request authenticate(Route route, Response response) throws IOException { //设置代理服务器账号密码 String credential = Credentials.basic("admin", "admin"); return response.request().newBuilder() .header("Proxy-Authorization", credential) .build(); } }); //如果要配置限制域则加上下面 /*List 
  
    proxyList = new ArrayList<>(1); proxyList.add(proxy); builder.proxySelector(new ProxySelector() { //限制域 Set 
   
     domainList; @Override public List 
    
      select(URI uri) { if (uri == null || !domainList.contains(uri.getHost())) { return Collections.singletonList(Proxy.NO_PROXY); } return proxyList; } @Override public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { } });*/ } } } 
     
    
  

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/202055.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月20日 上午7:59
下一篇 2026年3月20日 上午7:59


相关推荐

  • REST接口规范总结

    REST接口规范总结REST 接口规范总结

    2026年3月17日
    2
  • servlet和jsp的区别_获取servletcontext

    servlet和jsp的区别_获取servletcontext关于serveletContext.getRealPath()方法1.关于request.getRealPath问题:Stringfilename=request.getRealPath(filename)——————-信息:warning:[deprecation]getRealPath(java.lang.String)in

    2026年1月23日
    3
  • OpenClaw“龙虾”安装部署实践:腾讯与扣子平台的技术生态解析

    OpenClaw“龙虾”安装部署实践:腾讯与扣子平台的技术生态解析

    2026年3月13日
    2
  • ccd视觉定位教程_CCD视觉定位识别系统,视觉系统ccd定位原理[通俗易懂]

    ccd视觉定位教程_CCD视觉定位识别系统,视觉系统ccd定位原理[通俗易懂]CCD机器视觉系统是用于工业检测及识别的高科技产品,生产的核心问题是工业计算机系统选型,可采集加工品的高清图像直接传输给到机子的GPIO接口。由于数字图像处理和计算机视觉技术的迅速发展,越来越多的研究者采用摄像机作为全自主用移动机器人的感知传感器。这主要是因为原来的超声或红外传感器感知信息量有限,鲁棒性差,而视觉系统则可以弥补这些缺点。而现实世界是三维的,而投射于摄像镜头(CCD/CMOS)上的图…

    2022年6月15日
    88
  • 学习Java编程入门书籍

    学习Java编程入门书籍分享几本java编程入门书籍,文章转自知乎路人甲《HeadFirstJava》《HeadFirstJava》被亚马逊评为十大好书之一。在京东计算机类书籍中热度排名第16位,在Java类书籍中排名第2位。豆瓣评分为8.8分,有百分之54.4%的读者给出了五星评价。在知乎社区中有来自无数位的大神做推荐。哪本书适合推荐给Java初学者?-书籍推荐《HeadFirstJava》…

    2022年6月14日
    39
  • python nonlocal 什么意思_python nonlocal的理解使用

    python nonlocal 什么意思_python nonlocal的理解使用nonlocal 可以将一个变量声明为非本地变量 在 python 的 lru cache 看到了使用 defdecorator func a 1defwrapper args kwargs nonlocalaa 1returnfunc returnwrappe 实例中 当 a 变量是不可变类型时 因为包装函数引用了 a 装饰器执行结束 在包装函数里改变 a 的值 需要

    2025年9月4日
    4

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号