RestTemplate.getForObject处理未找到异常404

时间:2019-04-29 18:16:19

标签: spring-boot resttemplate

我正在做sso,并使用restTemplate.getForObject从服务器接收令牌。但是结果总是处理未找到的异常,尽管在服务器中我打印了令牌的值。服务器位于8081端口。下面是我的代码

Api:

@RequestMapping(value = "/getJwtToken", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
public String getJwtToken() {
    System.out.println("token store " + this.jwtTokenStore); //Here it printed: token store eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0c3NvIiwiaWF0IjoxNTU2NTYxMDc2fQ.ga7vQ81NwFY8d84fWOfBMtsIhWgzyUo5ymWFi1s6juU
    return jwtTokenStore;
}

客户:

RestTemplate rest1 = new RestTemplate();
try {
        String getJwtTokenFromServer = rest1.getForObject("http://localhost:8081/getJwtToken", String.class);
        System.out.println("jwtFromServer: " + getJwtTokenFromServer);
        if(getJwtTokenFromServer != null) CookieUtil.create(response, jwtTokenCookieName, getJwtTokenFromServer, false, -1, domainClient);
    } catch (Exception e) {
        // TODO: handle exception
        System.out.println(e.toString());
    }

它总是打印e.toString值。

0 个答案:

没有答案