【问题标题】:Return specific RestTemplate bean, how?返回具体的 RestTemplate bean,如何?
【发布时间】:2021-11-02 15:40:24
【问题描述】:

我想将 SSL 证书加载到 resttemplate 并使用它。但是我正在处理的项目已经有一个用于项目不同部分的resttemplate bean。我想要一个加载了特定 ssl 证书的 resttemplate,我想在应用程序的特定部分使用它。如何做到这一点?

【问题讨论】:

  • 你已经有第二个RestTemplate了吗?

标签: spring spring-boot javabeans resttemplate


【解决方案1】:

您可以简单地创建另一个RestTemplate bean:

@Configuration
class MyConfiguration {
    
    @Bean
    public RestTemplate sslCertRestTemplate() {
        RestTemplate restTemplate = // create your specific rest template
        return restTemplate;
    }
}

你可以使用@Qualifier注解注入这个sslCertRestTemplate

@Qualifier("sslCertRestTemplate")
@Autowired
private RestTemplate restTemplate;

【讨论】:

    猜你喜欢
    • 2018-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多