Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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
Java 重写应用于RestTemplate的RestTemplateCustomizer_Java_Spring Boot_Resttemplate_Apache Httpclient 4.x - Fatal编程技术网

Java 重写应用于RestTemplate的RestTemplateCustomizer

Java 重写应用于RestTemplate的RestTemplateCustomizer,java,spring-boot,resttemplate,apache-httpclient-4.x,Java,Spring Boot,Resttemplate,Apache Httpclient 4.x,我正在使用restemplatecustomizer为我的一个应用程序的restemplate配置公共配置。但是现在在我的一个客户机类中,我需要用一个不同的拦截器覆盖一个自定义拦截器 我可以在不使用restemplatebuilder的情况下获得restemplatebuilder的实例,并在此处添加我的所有配置,这些配置应该可以工作,但我真的不想要这种方法 解决这个问题的方法是将所有拦截器连接到restemplate,找到我的自定义拦截器1,删除它并添加新的自定义拦截器2 public My

我正在使用
restemplatecustomizer
为我的一个应用程序的
restemplate
配置公共配置。但是现在在我的一个客户机类中,我需要用一个不同的拦截器覆盖一个自定义拦截器

我可以在不使用
restemplatebuilder
的情况下获得
restemplatebuilder
的实例,并在此处添加我的所有配置,这些配置应该可以工作,但我真的不想要这种方法

解决这个问题的方法是将所有拦截器连接到
restemplate
,找到我的自定义拦截器1,删除它并添加新的自定义拦截器2

 public MyRestClient( RestTemplateBuilder restTemplateBuilder) {
        this.restTemplate = restTemplateBuilder.build();
        for(int i=0 ;i<this.restTemplate.getInterceptors().size();i++) {    
            if(this.restTemplate.getInterceptors().get(i).getClass().getSimpleName().equalsIgnoreCase("MyCustomInterceptor1")){
                this.restTemplate.getInterceptors().remove(i);
            }

        }

        this.restTemplate.getInterceptors().add(new MyCustomInterceptor2());
    }
公共MyRestClient(RestTemplateBuilder RestTemplateBuilder){
this.restTemplate=restTemplateBuilder.build();
对于(int i=0;i