Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring rest模板中IP地址和域名的不同场景_Spring_Resttemplate - Fatal编程技术网

Spring rest模板中IP地址和域名的不同场景

Spring rest模板中IP地址和域名的不同场景,spring,resttemplate,Spring,Resttemplate,我有一个rest模板代码,如下所示: HttpHeaders headers = new HttpHeaders(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if(authentication != null) { Collection<? extends GrantedAuthority> authoritie

我有一个rest模板代码,如下所示:

  HttpHeaders headers = new HttpHeaders();
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if(authentication != null) {
        Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
        if (!authorities.contains(new SimpleGrantedAuthority(ROLE_ANONYMOUS_USER))) {
            OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) authentication.getDetails();
            OAuth2AccessToken accessToken = tokenStore.readAccessToken(details.getTokenValue());
            headers.set(AUTHORIZATION, BEARER + accessToken);
        }
    }
  ResponseEntity<Foo> responseEntity =  restTemplate.exchange(<Domain name> + "/foo/1"
 , HttpMethod.GET, new HttpEntity(headers) , Foo.class);
HttpHeaders=newhttpheaders();
身份验证=SecurityContextHolder.getContext().getAuthentication();
if(身份验证!=null){
收集
 <Domain name> + "/foo/1"