小编Sud*_*kar的帖子

java.net.SocketException:Spring Rest 模板中的连接重置

我这里有一个奇怪的问题。

下面的代码工作正常,直到我在客户端重新启动 tomcat 服务器。一旦我使用相同代码的最新war文件重新启动tomcat服务器(客户端程序在war文件中),它会抛出以下错误。我正在使用 JDK 8。

下面是示例代码。从浏览器中,我能够从以下程序中使用的 URL 获得响应。但也无法使用 java 程序或 Postman 获取数据。

package com.example.demo;

import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

@Component
public class TestService implements CommandLineRunner {

    @Override
    public void run(String... args) throws Exception {
        download();
    }
    
    private void download() {
        System.out.println("Started download");
        try {
            RestTemplate restTemplate = new RestTemplate();
            String url = "https://www.nseindia.com/live_market/dynaContent/live_watch/stock_watch/niftyStockWatch.json";
            byte[] forObject = restTemplate.getForObject(url, byte [].class);
            System.out.println(forObject);
            System.out.println("Downloaded");
        } catch (Exception e) {
            System.out.println("Exception " + e);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是引发的异常:

org.springframework.web.client.ResourceAccessException: I/O error on …
Run Code Online (Sandbox Code Playgroud)

java tcp httpclient java-8 spring-boot

8
推荐指数
1
解决办法
7000
查看次数

标签 统计

httpclient ×1

java ×1

java-8 ×1

spring-boot ×1

tcp ×1