类org.springframework.http.client.ClientHttpRequestInterceptor源码实例Demo

下面列出了怎么用org.springframework.http.client.ClientHttpRequestInterceptor的API类实例代码及写法,或者点击链接到github查看源代码。

@Test
public void checkInterceptorHasNoAuthorizationHeaderPresent() {
	ConfigClientProperties defaults = new ConfigClientProperties(this.environment);
	defaults.getHeaders().put(AUTHORIZATION, "Basic dXNlcm5hbWU6cGFzc3dvcmQNCg==");
	defaults.getHeaders().put("key", "value");
	this.locator = new ConfigServicePropertySourceLocator(defaults);
	RestTemplate restTemplate = ReflectionTestUtils.invokeMethod(this.locator,
			"getSecureRestTemplate", defaults);
	Iterator<ClientHttpRequestInterceptor> iterator = restTemplate.getInterceptors()
			.iterator();
	while (iterator.hasNext()) {
		GenericRequestHeaderInterceptor genericRequestHeaderInterceptor = (GenericRequestHeaderInterceptor) iterator
				.next();
		assertThat(genericRequestHeaderInterceptor.getHeaders().get(AUTHORIZATION))
				.isEqualTo(null);
	}
}
 
源代码2 项目: spring-analysis-note   文件: RestTemplateTests.java
@Test  // SPR-15066
public void requestInterceptorCanAddExistingHeaderValueWithoutBody() throws Exception {
	ClientHttpRequestInterceptor interceptor = (request, body, execution) -> {
		request.getHeaders().add("MyHeader", "MyInterceptorValue");
		return execution.execute(request, body);
	};
	template.setInterceptors(Collections.singletonList(interceptor));

	HttpHeaders requestHeaders = new HttpHeaders();
	mockSentRequest(POST, "https://example.com", requestHeaders);
	mockResponseStatus(HttpStatus.OK);

	HttpHeaders entityHeaders = new HttpHeaders();
	entityHeaders.add("MyHeader", "MyEntityValue");
	HttpEntity<Void> entity = new HttpEntity<>(null, entityHeaders);
	template.exchange("https://example.com", POST, entity, Void.class);
	assertThat(requestHeaders.get("MyHeader"), contains("MyEntityValue", "MyInterceptorValue"));

	verify(response).close();
}
 
private void assertInterceptorsOrder(
		List<ClientHttpRequestInterceptor> interceptors) {
	int traceInterceptorIndex = -1;
	int myInterceptorIndex = -1;
	int mySecondInterceptorIndex = -1;
	Map<Class, Integer> numberOfInstances = new HashMap<>();
	for (int i = 0; i < interceptors.size(); i++) {
		ClientHttpRequestInterceptor interceptor = interceptors.get(i);
		incrementNumberOfInstances(numberOfInstances, interceptor);
		if (interceptor instanceof TracingClientHttpRequestInterceptor
				|| interceptor instanceof LazyTracingClientHttpRequestInterceptor) {
			traceInterceptorIndex = i;
		}
		else if (interceptor instanceof MyClientHttpRequestInterceptor) {
			myInterceptorIndex = i;
		}
		else if (interceptor instanceof MySecondClientHttpRequestInterceptor) {
			mySecondInterceptorIndex = i;
		}
	}
	then(traceInterceptorIndex).isGreaterThanOrEqualTo(0)
			.isLessThan(myInterceptorIndex).isLessThan(mySecondInterceptorIndex);
	then(numberOfInstances.values())
			.as("Can't have duplicate entries for interceptors")
			.containsOnlyElementsOf(Collections.singletonList(1));
}
 
源代码4 项目: zfile   文件: OneDriveConfig.java
/**
 * OneDrive 请求 RestTemplate, 会在请求头中添加 Bearer: Authorization {token} 信息, 用于 API 认证.
 */
@Bean
public RestTemplate oneDriveRestTemplate() {
    RestTemplate restTemplate = new RestTemplate();

    ClientHttpRequestInterceptor interceptor = (httpRequest, bytes, clientHttpRequestExecution) -> {
        HttpHeaders headers = httpRequest.getHeaders();
        Integer driveId = Integer.valueOf(((LinkedList)headers.get("driveId")).get(0).toString());

        StorageConfig accessTokenConfig =
                storageConfigService.findByDriveIdAndKey(driveId, StorageConfigConstant.ACCESS_TOKEN_KEY);

        String tokenValue = String.format("%s %s", "Bearer", accessTokenConfig.getValue());
        httpRequest.getHeaders().add("Authorization", tokenValue);
        return clientHttpRequestExecution.execute(httpRequest, bytes);
    };
    restTemplate.setInterceptors(Collections.singletonList(interceptor));
    return restTemplate;
}
 
源代码5 项目: java-technology-stack   文件: RestTemplateTests.java
@Test  // SPR-15066
public void requestInterceptorCanAddExistingHeaderValueWithoutBody() throws Exception {
	ClientHttpRequestInterceptor interceptor = (request, body, execution) -> {
		request.getHeaders().add("MyHeader", "MyInterceptorValue");
		return execution.execute(request, body);
	};
	template.setInterceptors(Collections.singletonList(interceptor));

	HttpHeaders requestHeaders = new HttpHeaders();
	mockSentRequest(POST, "http://example.com", requestHeaders);
	mockResponseStatus(HttpStatus.OK);

	HttpHeaders entityHeaders = new HttpHeaders();
	entityHeaders.add("MyHeader", "MyEntityValue");
	HttpEntity<Void> entity = new HttpEntity<>(null, entityHeaders);
	template.exchange("http://example.com", POST, entity, Void.class);
	assertThat(requestHeaders.get("MyHeader"), contains("MyEntityValue", "MyInterceptorValue"));

	verify(response).close();
}
 
源代码6 项目: java-technology-stack   文件: RestTemplateTests.java
@Test  // SPR-15066
public void requestInterceptorCanAddExistingHeaderValueWithBody() throws Exception {
	ClientHttpRequestInterceptor interceptor = (request, body, execution) -> {
		request.getHeaders().add("MyHeader", "MyInterceptorValue");
		return execution.execute(request, body);
	};
	template.setInterceptors(Collections.singletonList(interceptor));

	MediaType contentType = MediaType.TEXT_PLAIN;
	given(converter.canWrite(String.class, contentType)).willReturn(true);
	HttpHeaders requestHeaders = new HttpHeaders();
	mockSentRequest(POST, "http://example.com", requestHeaders);
	mockResponseStatus(HttpStatus.OK);

	HttpHeaders entityHeaders = new HttpHeaders();
	entityHeaders.setContentType(contentType);
	entityHeaders.add("MyHeader", "MyEntityValue");
	HttpEntity<String> entity = new HttpEntity<>("Hello World", entityHeaders);
	template.exchange("http://example.com", POST, entity, Void.class);
	assertThat(requestHeaders.get("MyHeader"), contains("MyEntityValue", "MyInterceptorValue"));

	verify(response).close();
}
 
源代码7 项目: training   文件: Oauth2ClientApplication.java
@Bean
RestTemplate restTemplate(OAuth2AuthorizedClientService clientService) {
		return new RestTemplateBuilder()
			.interceptors((ClientHttpRequestInterceptor) (httpRequest, bytes, execution) -> {

					OAuth2AuthenticationToken token = OAuth2AuthenticationToken.class.cast(
						SecurityContextHolder.getContext().getAuthentication());

					OAuth2AuthorizedClient client = clientService.loadAuthorizedClient(
						token.getAuthorizedClientRegistrationId(),
						token.getName());

					httpRequest.getHeaders().add(HttpHeaders.AUTHORIZATION, "Bearer " + client.getAccessToken().getTokenValue());

					return execution.execute(httpRequest, bytes);
			})
			.build();
}
 
/**
 * Adapt the instance of {@link DubboTransporterInterceptor} to the
 * {@link LoadBalancerInterceptor} Bean.
 * @param restTemplate {@link LoadBalanced @LoadBalanced} {@link RestTemplate} Bean
 * @param dubboTranslatedAttributes the annotation dubboTranslatedAttributes
 * {@link RestTemplate} bean being annotated
 * {@link DubboTransported @DubboTransported}
 */
private void adaptRestTemplate(RestTemplate restTemplate,
		Map<String, Object> dubboTranslatedAttributes) {

	List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>(
			restTemplate.getInterceptors());

	int index = loadBalancerInterceptorBean == null ? -1
			: interceptors.indexOf(loadBalancerInterceptorBean);

	index = index < 0 ? 0 : index;

	// Add ClientHttpRequestInterceptor instances before loadBalancerInterceptor
	interceptors.add(index++, new DubboMetadataInitializerInterceptor(repository));

	interceptors.add(index++,
			new DubboTransporterInterceptor(repository,
					restTemplate.getMessageConverters(), classLoader,
					dubboTranslatedAttributes, serviceFactory, contextFactory));

	restTemplate.setInterceptors(interceptors);
}
 
/**
 * Add any interceptors found in the application context, e.g. for logging, which may or may not be present
 * based on profiles.
 */
@Autowired(required = false)
@Override
public void setInterceptors(List<ClientHttpRequestInterceptor> interceptors) {

    if (interceptors.isEmpty()) {
        logger.info("No HTTP request interceptors have been found in the application context.");
        return;
    }

    for (ClientHttpRequestInterceptor interceptor : interceptors) {
        logger.info("The interceptor '{}' will be added to this provider.", interceptor.getClass().getSimpleName());
    }

    super.setInterceptors(interceptors);
}
 
源代码10 项目: chaos-lemur   文件: StandardDirectorUtils.java
private static RestTemplate createRestTemplate(String host, String username, String password, Set<ClientHttpRequestInterceptor> interceptors) throws GeneralSecurityException {
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope(host, 25555),
        new UsernamePasswordCredentials(username, password));

    SSLContext sslContext = SSLContexts.custom()
        .loadTrustMaterial(null, new TrustSelfSignedStrategy())
        .useTLS()
        .build();

    SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext, new AllowAllHostnameVerifier());

    HttpClient httpClient = HttpClientBuilder.create()
        .disableRedirectHandling()
        .setDefaultCredentialsProvider(credentialsProvider)
        .setSSLSocketFactory(connectionFactory)
        .build();

    RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient));
    restTemplate.getInterceptors().addAll(interceptors);

    return restTemplate;
}
 
源代码11 项目: sdk   文件: AviRestUtils.java
public static RestTemplate getRestTemplate(AviCredentials creds) {
	RestTemplate restTemplate = null;
	if (creds != null) {
		try {
			restTemplate = getInitializedRestTemplate(creds);
			restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory(getControllerURL(creds) + API_PREFIX));
			List<ClientHttpRequestInterceptor> interceptors = 
					Collections.<ClientHttpRequestInterceptor>singletonList(
							new AviAuthorizationInterceptor(creds));
			restTemplate.setInterceptors(interceptors);
			restTemplate.setMessageConverters(getMessageConverters(restTemplate));
			return restTemplate;
		} catch (Exception e) {
			LOGGER.severe("Exception during rest template initialization");

		}
	}
	return restTemplate;
}
 
/**
 * Init
 */
@PostConstruct
protected void init() {

    restTemplateForAuthenticationFlow = new CookieStoreRestTemplate();
    cookieStore = restTemplateForAuthenticationFlow.getCookieStore();

    logger.debug("Inject cookie store used in the rest template for authentication flow into the authRestTemplate so that they will match");
    authRestTemplate.restTemplate.setCookieStoreAndUpdateRequestFactory(cookieStore);

    List<ClientHttpRequestInterceptor> interceptors = Collections
            .<ClientHttpRequestInterceptor>singletonList(new ClientHttpRequestInterceptor() {
                @Override
                public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
                    if (latestCsrfToken != null) {
                        // At the beginning of auth flow, there's no token yet
                        injectCsrfTokenIntoHeader(request, latestCsrfToken);
                    }
                    return execution.execute(request, body);
                }
            });

    restTemplateForAuthenticationFlow.setRequestFactory(new InterceptingClientHttpRequestFactory(restTemplateForAuthenticationFlow.getRequestFactory(), interceptors));
}
 
@Bean
@Order(SOME_NOT_LOWEST_PRECEDENCE)
@Profile("bug")
public RestTemplateCustomizer someOrderedInterceptorCustomizer() {
	return new RestTemplateCustomizer() {
		@Override
		public void customize(RestTemplate restTemplate) {
			ClientHttpRequestInterceptor emptyInterceptor = new ClientHttpRequestInterceptor() {
				@Override
				public ClientHttpResponse intercept(HttpRequest request, byte[] body,
						ClientHttpRequestExecution execution) throws IOException {
					return execution.execute(request, body);
				}
			};
			restTemplate.getInterceptors().add(emptyInterceptor);
		}
	};
}
 
@Bean
public RestTemplateCustomizer someNotOrderedInterceptorCustomizer() {
	return new RestTemplateCustomizer() {
		@Override
		public void customize(RestTemplate restTemplate) {
			ClientHttpRequestInterceptor emptyInterceptor = new ClientHttpRequestInterceptor() {
				@Override
				public ClientHttpResponse intercept(HttpRequest request, byte[] body,
						ClientHttpRequestExecution execution) throws IOException {
					return execution.execute(request, body);
				}
			};
			restTemplate.getInterceptors().add(emptyInterceptor);
		}
	};
}
 
@Bean
@Order
public RestTemplateCustomizer someLowestPrecedenceOrderedInterceptorCustomizer() {
	return new RestTemplateCustomizer() {
		@Override
		public void customize(RestTemplate restTemplate) {
			ClientHttpRequestInterceptor emptyInterceptor = new ClientHttpRequestInterceptor() {
				@Override
				public ClientHttpResponse intercept(HttpRequest request, byte[] body,
						ClientHttpRequestExecution execution) throws IOException {
					return execution.execute(request, body);
				}
			};
			restTemplate.getInterceptors().add(emptyInterceptor);
		}
	};
}
 
源代码16 项目: computoser   文件: PurchaseService.java
@PostConstruct
public void init() {
    jsonMapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
    template.getInterceptors().add(new ClientHttpRequestInterceptor() {

        @Override
        public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
                throws IOException {
            request.getHeaders().add("Accept", "application/json");
            request.getHeaders().add("Content-Type", "application/json");
            request.getHeaders().add("User-Agent", "");
            return execution.execute(request, body);
        }
    });
    //paymentContext = new PaymillContext(secret);
}
 
源代码17 项目: spring-cloud-dataflow   文件: ConfigCommands.java
private ClientHttpRequestInterceptor bearerTokenResolvingInterceptor(
		OAuth2ClientProperties properties, String username, String password, String clientRegistrationId) {
	ClientRegistrationRepository shellClientRegistrationRepository = shellClientRegistrationRepository(properties);
	OAuth2AuthorizedClientService shellAuthorizedClientService = shellAuthorizedClientService(shellClientRegistrationRepository);
	OAuth2AuthorizedClientManager authorizedClientManager = authorizedClientManager(
			shellClientRegistrationRepository, shellAuthorizedClientService);

	if (properties.getRegistration() != null && properties.getRegistration().size() == 1) {
		// if we have only one, use that
		clientRegistrationId = properties.getRegistration().entrySet().iterator().next().getKey();
	}

	OAuth2AuthorizeRequest authorizeRequest = OAuth2AuthorizeRequest.withClientRegistrationId(clientRegistrationId)
			.principal(DEFAULT_PRINCIPAL)
			.attribute(OAuth2AuthorizationContext.USERNAME_ATTRIBUTE_NAME, username)
			.attribute(OAuth2AuthorizationContext.PASSWORD_ATTRIBUTE_NAME, password)
			.build();

	return (request, body, execution) -> {
		OAuth2AuthorizedClient authorizedClient = authorizedClientManager.authorize(authorizeRequest);
		request.getHeaders().setBearerAuth(authorizedClient.getAccessToken().getTokenValue());
		return execution.execute(request, body);
	};
}
 
private ClientHttpRequestInterceptor clientCredentialsTokenResolvingInterceptor(
		ClientRegistration clientRegistration, ClientRegistrationRepository clientRegistrationRepository,
		String clientId) {
	Authentication principal = createAuthentication(clientId);
	OAuth2AuthorizedClientService authorizedClientService = new InMemoryOAuth2AuthorizedClientService(
			clientRegistrationRepository);
	AuthorizedClientServiceOAuth2AuthorizedClientManager authorizedClientManager = new AuthorizedClientServiceOAuth2AuthorizedClientManager(
			clientRegistrationRepository, authorizedClientService);
	OAuth2AuthorizedClientProvider authorizedClientProvider = OAuth2AuthorizedClientProviderBuilder.builder()
			.clientCredentials().build();
	authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider);

	OAuth2AuthorizeRequest authorizeRequest = OAuth2AuthorizeRequest
			.withClientRegistrationId(DEFAULT_REGISTRATION_ID).principal(principal).build();

	return (request, body, execution) -> {
		OAuth2AuthorizedClient authorizedClient = authorizedClientManager.authorize(authorizeRequest);
		request.getHeaders().setBearerAuth(authorizedClient.getAccessToken().getTokenValue());
		return execution.execute(request, body);
	};
}
 
@Test
public void notSampledHeaderAddedWhenNotSampled() {
	this.tracing.close();
	this.tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
			.addSpanHandler(this.spans).sampler(Sampler.NEVER_SAMPLE).build();
	this.template.setInterceptors(Arrays.<ClientHttpRequestInterceptor>asList(
			TracingClientHttpRequestInterceptor.create(HttpTracing.create(tracing))));

	Span span = tracing.tracer().nextSpan().name("new trace");
	Map<String, String> headers;

	try (Tracer.SpanInScope ws = tracing.tracer().withSpanInScope(span.start())) {
		headers = this.template.getForEntity("/", Map.class).getBody();
	}
	finally {
		span.finish();
	}

	then(this.spans).isEmpty();
}
 
源代码20 项目: onetwo   文件: RestExecutorConfiguration.java
@Override
public void afterPropertiesSet() throws Exception {
	ExtRestTemplate restTemplate = (ExtRestTemplate) restExecutor;
	Map<String, Object> restExecutorInterceptors = applicationContext.getBeansWithAnnotation(RestExecutorInterceptor.class);
	if(!LangUtils.isEmpty(restExecutorInterceptors)){
		List<ClientHttpRequestInterceptor> interList = restTemplate.getInterceptors();
		if(interList==null){
			interList = Lists.newArrayList();
			restTemplate.setInterceptors(interList);
		}
		for(Entry<String, Object> entry : restExecutorInterceptors.entrySet()){
			if(logger.isDebugEnabled()){
				logger.debug("register ClientHttpRequestInterceptor for RestExecutor: {}", entry.getKey());
			}
			interList.add((ClientHttpRequestInterceptor)entry.getValue());
		}
		AnnotationAwareOrderComparator.sort(interList);
	}
}
 
@PostConstruct
public void init() {
  LOGGER.debug("init restTemplate for dtm..");
  if (this.restTemplates != null) {
    for (RestTemplate restTemplate : restTemplates) {
      List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>(
          restTemplate.getInterceptors());
      interceptors.add(dtmRestTemplateInterceptor);
      restTemplate.setInterceptors(interceptors);
    }
  }
}
 
源代码22 项目: spring-cloud-sleuth   文件: GH846Tests.java
public int listAndCount() {
	for (ClientHttpRequestInterceptor interceptor : this.restTemplate
			.getInterceptors()) {
		System.out.println(interceptor);
	}
	return this.restTemplate.getInterceptors().size();
}
 
@Test
public void getInterceptors() {
	TestInterceptingHttpAccessor accessor = new TestInterceptingHttpAccessor();
	List<ClientHttpRequestInterceptor> interceptors = Arrays.asList(
			new SecondClientHttpRequestInterceptor(),
			new ThirdClientHttpRequestInterceptor(),
			new FirstClientHttpRequestInterceptor()

	);
	accessor.setInterceptors(interceptors);

	assertThat(accessor.getInterceptors().get(0), Matchers.instanceOf(FirstClientHttpRequestInterceptor.class));
	assertThat(accessor.getInterceptors().get(1), Matchers.instanceOf(SecondClientHttpRequestInterceptor.class));
	assertThat(accessor.getInterceptors().get(2), Matchers.instanceOf(ThirdClientHttpRequestInterceptor.class));
}
 
源代码24 项目: tutorials   文件: RestTemplateLoggingLiveTest.java
@Test
public void givenLoggingInterceptorConfiguration_whenSendGetForRequestEntity_thenRequestResponseCustomLog() {

    RestTemplate restTemplate = new RestTemplate();
    List<ClientHttpRequestInterceptor> interceptors = restTemplate.getInterceptors();
    if (CollectionUtils.isEmpty(interceptors)) {
        interceptors = new ArrayList<>();
    }
    interceptors.add(new LoggingInterceptor());
    restTemplate.setInterceptors(interceptors);

    final ResponseEntity<String> response = restTemplate.postForEntity(baseUrl + "/persons", "my request body", String.class);
    assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
}
 
源代码25 项目: txle   文件: RestTemplateConfig.java
@Bean
public RestTemplate restTemplate(@Autowired(required = false) OmegaContext context, @Autowired Tracing tracing) {
  RestTemplate template = new RestTemplate();
  List<ClientHttpRequestInterceptor> interceptors = template.getInterceptors();
  interceptors.add(new TransactionClientHttpRequestInterceptor(context));
  // add interceptor for rest's request server By Gannalyo
  interceptors.add(TracingClientHttpRequestInterceptor.create(tracing));
  template.setInterceptors(interceptors);
  return template;
}
 
void inject(RestTemplate restTemplate) {
	if (hasTraceInterceptor(restTemplate)) {
		return;
	}
	List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>(
			restTemplate.getInterceptors());
	interceptors.add(0, this.interceptor);
	restTemplate.setInterceptors(interceptors);
}
 
ClientHttpRequestFactory configureClient(ClientHttpRequestInterceptor interceptor) {
  HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
  factory.setReadTimeout(1000);
  factory.setConnectTimeout(1000);
  this.interceptor = interceptor;
  return factory;
}
 
private HttpRequest invokeInterceptors(RestOperations restOperations)
		throws IOException {
	assertThat(restOperations).isInstanceOf(RestTemplate.class);
	RestTemplate restTemplate = (RestTemplate) restOperations;

	MockClientHttpRequest request = new MockClientHttpRequest();
	ClientHttpRequestExecution execution = Mockito
			.mock(ClientHttpRequestExecution.class);
	byte[] body = new byte[] {};
	for (ClientHttpRequestInterceptor interceptor : restTemplate.getInterceptors()) {
		interceptor.intercept(request, body, execution);
	}
	return request;
}
 
@Test
public void getInterceptors() {
	TestInterceptingHttpAccessor accessor = new TestInterceptingHttpAccessor();
	List<ClientHttpRequestInterceptor> interceptors = Arrays.asList(
			new SecondClientHttpRequestInterceptor(),
			new ThirdClientHttpRequestInterceptor(),
			new FirstClientHttpRequestInterceptor()

	);
	accessor.setInterceptors(interceptors);

	assertThat(accessor.getInterceptors().get(0), Matchers.instanceOf(FirstClientHttpRequestInterceptor.class));
	assertThat(accessor.getInterceptors().get(1), Matchers.instanceOf(SecondClientHttpRequestInterceptor.class));
	assertThat(accessor.getInterceptors().get(2), Matchers.instanceOf(ThirdClientHttpRequestInterceptor.class));
}
 
@Bean
public UserInfoRestTemplateCustomizer retryLoadBalancedUserInfoRestTemplateCustomizer(
		final RetryLoadBalancerInterceptor loadBalancerInterceptor) {
	return new UserInfoRestTemplateCustomizer() {
		@Override
		public void customize(OAuth2RestTemplate restTemplate) {
			List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>(
					restTemplate.getInterceptors());
			interceptors.add(loadBalancerInterceptor);
			restTemplate.setInterceptors(interceptors);
		}
	};
}
 
 类所在包
 类方法
 同包方法