3

Below is my bootstrap.yml file:

spring.application.name: backend
spring.cloud.vault:
  host: localhost
  port: 8200
  scheme: http
  authentication: token
  token: root

My secrets are located at secret/backend

enter image description here

I am trying to read these secrets in a controller class like so:

    @Value("${masterpassword}")
    private String masterPassword;

but this leads to IllegalArgumentException as spring complains it cannot find any masterpassword:

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'secretsController': Injection of autowired dependencies failed; 
nested exception is java.lang.IllegalArgumentException: 
Could not resolve placeholder 'masterpassword' in value "${masterpassword}"

Can someone please tell me what I am doing wrong? Thanks for your help :)

Somjit
  • 2,503
  • 5
  • 33
  • 60

2 Answers2

0

For me downgrading the spring boot version works. I changed the parent version to: <version>2.3.0.RELEASE</version> and the spring cloud version to: <spring-cloud.version>Hoxton.SR1</spring-cloud.version>

f.trajkovski
  • 794
  • 9
  • 24
  • That cannot possibly be the solution right ? – Alexis Feb 24 '21 at 12:46
  • @Alexis I know that it's not a solution, but there isn't much documentation and I think that everything needs to be posted that might be a solution. For my case I needed for demo purpose so I didn't care about the spring boot version. – f.trajkovski Nov 25 '21 at 15:30
0

Depending on the spring boot version you are using, you might have to use spring.config.import: vault:// in your configuration file (which by the way can be deprecated):

With Spring Cloud Vault 3.0 and Spring Boot 2.4, the bootstrap context initialization (bootstrap.yml, bootstrap.properties) of property sources was deprecated. Instead, Spring Cloud Vault favors Spring Boot’s Config Data API which allows importing configuration from Vault.

https://docs.spring.io/spring-cloud-vault/docs/current/reference/html/#client-side-usage

Ninroot
  • 61
  • 1
  • 8