0

我正在尝试在 bean 中运行 Vault 容器并将其用于创建 VaultTemplate bean 以进一步在测试中使用

@TestConfiguration
@TestPropertySource("classpath:application.yml")
public class TestsConfiguration {

    @Container
    public static VaultContainer vaultContainer = new VaultContainer();


    @Bean
    @Order(1)
    public VaultEndpoint vaultEndpoint() {
        vaultContainer
                .withVaultToken("00000000-0000-0000-0000-000000000000")
                .withExposedPorts(8200);
        vaultContainer.start();
        return VaultEndpoint.create(vaultContainer.getContainerIpAddress(), vaultContainer.getMappedPort(8200));
    }

    @Bean
    @Order(2)
    public VaultTemplate vaultTemplate(VaultEndpoint vaultEndpoint) {
        return new VaultTemplate(vaultEndpoint, new TokenAuthentication("00000000-0000-0000-0000-000000000000"));
    }


}

但是,当我尝试通过 VaultOperations 编写一些 kv 时,我得到:

“https://localhost:32998/v1/my/secret”的 GET 请求上的 I/O 错误:无法识别的 SSL 消息,明文连接?嵌套异常是 javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?

我怎么解决这个问题?

4

1 回答 1

1
@TestConfiguration
@TestPropertySource("classpath:application.yml")
public class TestsConfiguration {

    @Container
    public static VaultContainer vaultContainer = new VaultContainer();


    @Bean
    public VaultEndpoint vaultEndpoint() {
        vaultContainer
                .withVaultToken("00000000-0000-0000-0000-000000000000")
                .withExposedPorts(8200);
        vaultContainer.start();
        return VaultEndpoint.create(vaultContainer.getContainerIpAddress(), vaultContainer.getMappedPort(8200));
    }

    @Bean
    public VaultTemplate vaultTemplate(VaultEndpoint vaultEndpoint) {
    vaultEndpoint.setScheme("http"); ////////////// this
    return new VaultTemplate(vaultEndpoint, new TokenAuthentication("00000000-0000-0000-0000-000000000000"));
    }


}
于 2020-10-06T10:13:21.533 回答