1

****错误:**连接到保险库但未从保险库中检索存储的机密** myclass.java,如下所示:

    @SpringBootApplication
    public class HelloSpringVaultApplication {  
        public static void main(String[] args) {
            SpringApplication.run(HelloSpringVaultApplication.class, args);
        }
        @Value("${key}")
        String key; 
        @Value("${value}")
        String value;   
        @PostConstruct
        public void postConstruct() {
            System.out.println("============================");
            System.out.println(key);
            System.out.println(value);
            System.out.println("============================");
        }
    }

application.properties 文件:

    vault.uri=http://localhost:8200
    vault.token=12345
    key=
    value=

bootstrap.yaml 文件:

    spring.application.name: hello-spring-vault
    spring.cloud.vault:
        host: localhost
        port: 8200
        scheme: http
        authentication: TOKEN
        token: 12345

VaultConfig 文件:

    @Configuration
    @VaultPropertySource("secret/hello-spring-vault")
    public class VaultConfig extends AbstractVaultConfiguration {
        //@Autowired
        //Environment environment;  
        @Override
        public VaultEndpoint vaultEndpoint() {
            String uri = getEnvironment().getProperty("vault.uri");
            if (uri != null) {
                System.out.println(uri);
                System.out.println("we are at uri");
                return VaultEndpoint.from(URI.create(uri));
            }
            // ...
            throw new IllegalStateException();
        }

        /**
         * Configure a client authentication. Please consider a more secure
         * authentication method for production use.
         */
        @Override
        public ClientAuthentication clientAuthentication() {
            String token = getEnvironment().getProperty("vault.token");
            if (token != null) {
                System.out.println(token);
                return new TokenAuthentication(token);
            }
            // ...
            throw new IllegalStateException();
        }
    }

错误

            .   ____          _            __ _ _
             /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
            ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
             \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
              '  |____| .__|_| |_|_| |_\__, | / / / /
             =========|_|==============|___/=/_/_/_/
             :: Spring Boot ::        (v2.0.4.RELEASE)

    2018-09-17 23:00:57.001  INFO 5344 --- [main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='vault', propertySources=[LeaseAwareVaultPropertySource {name='secret/hello-spring-vault'}, LeaseAwareVaultPropertySource {name='secret/application'}]}
    2018-09-17 23:00:57.012  INFO 5344 --- [main] s.h.HelloSpringVaultApplication  : No active profile set, falling back to default profiles: default
    2018-09-17 23:00:57.035  INFO 5344 --- [main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@46d8f407: startup date [Mon Sep 17 23:00:57 EDT 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@51972dc7
    2018-09-17 23:00:57.375  INFO 5344 --- [main] o.s.cloud.context.scope.GenericScope: BeanFactory id=829f8997-cef0-3b7b-8ed9-3fa5b3183168
    http://localhost:8200
    12345
    2018-09-17 23:00:57.412  INFO 5344 --- [main] o.s.s.c.ThreadPoolTaskScheduler  : Initializing ExecutorService  'threadPoolTaskScheduler'
    http://localhost:8200
    2018-09-17 23:00:57.461  INFO 5344 --- [main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$45b948cc] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    ============================

    ============================
    2018-09-17 23:00:59.574  INFO 5344 --- [main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
    2018-09-17 23:00:59.736  INFO 5344 --- main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
    2018-09-17 23:00:59.767  INFO 5344 --- [main] o.s.j.e.a.AnnotationMBeanExporter: Bean with name 'configurationPropertiesRebinder' has been autodetected for JMX exposure
    2018-09-17 23:00:59.769  INFO 5344 --- [main] o.s.j.e.a.AnnotationMBeanExporter: Bean with name 'environmentManager' has been autodetected for JMX exposure
    2018-09-17 23:00:59.772  INFO 5344 --- [main] o.s.j.e.a.AnnotationMBeanExporter: Bean with name 'refreshScope' has been autodetected for JMX exposure
    2018-09-17 23:00:59.781  INFO 5344 --- [main] o.s.j.e.a.AnnotationMBeanExporter: Located managed bean 'environmentManager': registering with JMX server as MBean [org.springframework.cloud.context.environment:name=environmentManager,type=EnvironmentManager]
    2018-09-17 23:00:59.833  INFO 5344 --- [main] o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'refreshScope': registering with JMX server as MBean [org.springframework.cloud.context.scope.refresh:name=refreshScope,type=RefreshScope]
    2018-09-17 23:00:59.859  INFO 5344 --- [main] o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'configurationPropertiesRebinder': registering with JMX server as MBean [org.springframework.cloud.context.properties:name=configurationPropertiesRebinder,context=46d8f407,type=ConfigurationPropertiesRebinder]
    2018-09-17 23:00:59.926  INFO 5344 --- [main] s.h.HelloSpringVaultApplication : Started HelloSpringVaultApplication in 7.923 seconds (JVM running for 9.31)
    2018-09-17 23:00:59.934  INFO 5344 --- [Thread-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@51972dc7: startup date [Mon Sep 17 23:00:54 EDT 2018]; root of context hierarchy
    2018-09-17 23:00:59.935  INFO 5344 --- [Thread-5] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@46d8f407: startup date [Mon Sep 17 23:00:57 EDT 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@51972dc7
    2018-09-17 23:00:59.942  INFO 5344 --- [Thread-5] o.s.j.e.a.AnnotationMBeanExport: Unregistering JMX-exposed beans on shutdown
    2018-09-17 23:00:59.944  INFO 5344 --- [Thread-5] o.s.j.e.a.AnnotationMBeanExporter  : Unregistering JMX-exposed beans
    2018-09-17 23:00:59.947  INFO 5344 --- [Thread-5] o.s.s.c.ThreadPoolTaskScheduler   : Shutting down ExecutorService 'threadPoolTaskScheduler'
    2018-09-17 23:00:59.950  INFO 5344 --- [Thread-1]o.s.s.c.ThreadPoolTaskScheduler  : Shutting down ExecutorService

我是 Java spring 应用程序的新手。请让我知道如何从保险库中检索存储的值?

谢谢,Akhila***强烈的文字***

4

0 回答 0