openFeign配合nacos服务发现进行微服务调用返回503 service unavailable

openFeign配合nacos服务发现进行微服务调用返回503 service unavailable

出现问题的远程接口代码

@FeignClient("targetService")
public interface FeignService {
   
    @GetMapping("/xxxx/xxxx/xxxx/list")
    public R callService();
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
可以通过以下步骤实现FeignNacos的https微服务调用: 1. 在Nacos中配置https协议的微服务实例,确保服务已经正常运行。 2. 在Feign客户端中配置https请求的方式,可以参考以下代码: ```java @Configuration public class FeignHttpsConfig { @Bean public OkHttpClient okHttpClient() { return new OkHttpClient.Builder() .sslSocketFactory(createSSLSocketFactory()) .hostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } }) .build(); } private SSLSocketFactory createSSLSocketFactory() { SSLSocketFactory sslSocketFactory = null; try { SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, new TrustManager[]{new X509TrustManager() { @Override public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { } @Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } @Override public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } }}, new SecureRandom()); sslSocketFactory = sslContext.getSocketFactory(); } catch (Exception e) { e.printStackTrace(); } return sslSocketFactory; } } ``` 3. 在Feign客户端中使用@FeignClient注解指定微服务名称,并通过@RequestLine注解指定https请求的方式,例如: ```java @FeignClient(name = "example-service", configuration = FeignHttpsConfig.class) public interface ExampleFeignClient { @RequestLine("GET /example") String getExample(); } ``` 4. 在应用启动类中添加@EnableFeignClients注解,以启用Feign客户端。 5. 调用Feign客户端的方法即可实现https微服务调用

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值