无法在java中的单元测试期间禁用SpringVault

e3bfsja2  于 2021-07-11  发布在  Java
关注(0)|答案(1)|浏览(471)

我在单元测试中禁用了SpringVault。但是,它仍然支持它并在后台运行。这是我的密码。下面的代码有问题吗

@RunWith(SpringRunner.class)

@SpringBootTest(properties = "spring.cloud.vault.enabled=false", classes = 
 DummyTest.class)
public class DummyTest{

    @Test
    public void getDummyTest() throws Exception{
        assertTrue(true);
    }

}

以下是在控制台中打印的例外情况

Caused by: java.lang.IllegalArgumentException: Token (spring.cloud.vault.token) must not be empty
at org.springframework.util.Assert.hasText(Assert.java:287)
at org.springframework.cloud.vault.config.ClientAuthenticationFactory.createClientAuthentication(ClientAuthenticationFactory.java:108)
at org.springframework.cloud.vault.config.VaultBootstrapConfiguration.clientAuthentication(VaultBootstrapConfiguration.java:206)
at org.springframework.cloud.vault.config.VaultBootstrapConfiguration$$EnhancerBySpringCGLIB$$1d0bfc2.CGLIB$clientAuthentication$3(<generated>)
at org.springframework.cloud.vault.config.VaultBootstrapConfiguration$$EnhancerBySpringCGLIB$$1d0bfc2$$FastClassBySpringCGLIB$$7f75c921.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
at org.springframework.cloud.vault.config.VaultBootstrapConfiguration$$EnhancerBySpringCGLIB$$1d0bfc2.clientAuthentication(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 99 more
xmq68pz9

xmq68pz91#

我昨天也有同样的问题。此问题已解决:原因:java.lang.illegalargumentexception:token(spring.cloud.vault.token)不能为空-hashicorp vault
测试类在应用程序上下文中加载,但得到的错误在引导上下文中抛出。 spring.cloud -属性总是在该上下文中加载。解决办法是 spring.cloud.vault.enabled=false 在bootstrap上下文中,例如,您可以将它放在测试资源的bootstrap.yml文件中。

相关问题