Spoiled_duoduo 2021-12-27 01:21 采纳率: 50%
浏览 928
已结题

RestTemplate报ResourceAccessException的问题,求解答

2021-12-27 00:53:46.436 ERROR 7760 --- [nio-9093-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.client.ResourceAccessException: I/O error on GET request for "localhost://9092/user/out": unknown protocol: localhost; nested exception is java.net.MalformedURLException: unknown protocol: localhost] with root cause

@RestController
@RequestMapping("/consumer")
public class ConsumerController {

    private final RestTemplate restTemplate;

    public ConsumerController(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }
    @RequestMapping("/find")
    public String findAll(){
        String url="http://localhost://9092/user/out";
        String str = restTemplate.getForObject(url, String.class);
        System.out.println(str);
        return str;
    }
}

  • 写回答

2条回答 默认 最新

  • CSDN专家-sinJack 2021-12-27 08:02
    关注
    
    http://localhost:9092/user/out
    

    url是这么写吧

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 1月4日
  • 已采纳回答 12月27日
  • 创建了问题 12月27日

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度