使用 spring.config.import 时如何访问 OAuth2 安全的 Spring 云配置服务器?

问题描述 投票:0回答:0

我有一个使用 OAuth2 保护的 Spring Cloud 配置服务器,并使用旧式(pre-Spring 2.4)引导方法绑定到配置服务器。为了让它使用 OAuth2RestTemplate,我实现了一个自定义的

ConfigServicePropertySourceLocator
来设置其余模板,通过
spring.factories
配置(我在那里找到了一些展示如何执行此操作的示例):

@Configuration
public class ConfigClientOAuth2BootstrapConfiguration {

    @Bean
    @Primary
    public ConfigServicePropertySourceLocator configServicePropertySourceLocator() {
        ConfigClientProperties clientProperties = configClientProperties();
        ConfigServicePropertySourceLocator locator = new ConfigServicePropertySourceLocator(clientProperties);
        locator.setRestTemplate(oauth2RestTemplate());
        
        return locator;
    }

    [...]
}

META-INF/spring.factories:

org.springframework.cloud.bootstrap.BootstrapConfiguration=\
com.smartequip.config.ConfigClientOAuth2BootstrapConfiguration

这样一切都很好。

但我想使用新的 Spring Boot Config Data 导入方法

spring.config.import=optional:configserver:
而不是 2.4 中引入的方法(取消 bootstrap.properties,以及对
spring-cloud-starter-bootstrap
的需要),但找不到任何文档或示例关于如何在这种情况下设置自定义 Rest 模板。

有没有人有关于如何做到这一点的示例(或文档链接)?或者这不可能?

java spring oauth spring-cloud-config
© www.soinside.com 2019 - 2024. All rights reserved.