In my Vault and Consul integration i have following secrets engine enble
[root@user ConsulSetup]# vault secrets list -detailed
Path Plugin Accessor Default TTL Max TTL Force No Cache Replication Seal Wrap Options Description
---- ------ -------- ----------- ------- -------------- ----------- --------- ------- -----------
cubbyhole/ cubbyhole cubbyhole_f6352b88 n/a n/a false local false map[] per-token private secret storage
identity/ identity identity_9ba1824c system system false replicated false map[] identity store
kv/ kv kv_864b2492 system system false replicated false map[version:2] n/a
sys/ system system_0064db30 n/a n/a false replicated false map[] system endpoints used for control, policy and debugging
After this i added key/value from this command
vault kv put kv/demo/dev spring.datasource.username=demo-user-dev spring.datasource.password=demo-pass-dev
Now i want to read these value via SpringBoot Application so here is my bootstrap.yml file
spring:
cloud:
# Configuration for a vault server running in dev mode
vault:
scheme: http
host: <HOSTIP>
port: 8200
connection-timeout: 5000
read-timeout: 15000
authentication: TOKEN
token: <TOKEN>
kv.enabled: true
generic:
enabled: true
backend: kv
profile-separator: '/'
logging:
level:
ROOT: WARN
Now i am trying to run the code
package com.example.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import java.sql.SQLException;
import static org.springframework.util.Assert.isTrue;
@SpringBootApplication
public class DemoApplication {
@Value("${spring.profiles.active:#{null}}")
private String profiles;
@Value("${spring.datasource.username}")
private String username;
@Value("${spring.datasource.password}")
private String password;
@Value("${other.username}")
private String other;
@Autowired
private DataSource dataSource;
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@PostConstruct
private void postConstruct() throws SQLException {
System.out.println("##########################");
System.out.println("profile(s): " + profiles);
System.out.println("username: " + username);
System.out.println("password: " + password);
System.out.println("other: " + other);
dataSource.getConnection();
System.out.println("Successfully connected to database");
System.out.println("##########################");
isTrue (!username.equals("to-be-overwritten-by-vault-value"), "Username " + username);
isTrue (!password.equals("to-be-overwritten-by-vault-value"), "Password " + password);
}
}
Which is end with following error
#################### profile(s): null username: to-be-overwritten-by-vault-value password:to-be-overwritten-by-vault-value other: to-be-overwritten-by-vault-value Successfully connected to database
#################### 2019-05-30 15:31:39.147 WARN 18680 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encounteredduring context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'demoApplication': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Username to-be-overwritten-by-vault-value 2019-05-30 15:31:39.178 ERROR 18680 --- [ main] o.s.boot.SpringApplication
: Application startup failedorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'demoApplication': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Username to-be-overwritten-by-vault-value at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:137) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:409) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1620) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.4.RELEASE.jar:1.5.4.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.4.RELEASE.jar:1.5.4.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.4.RELEASE.jar:1.5.4.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.4.RELEASE.jar:1.5.4.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.4.RELEASE.jar:1.5.4.RELEASE] at com.example.demo.DemoApplication.main(DemoApplication.java:33) [classes/:na] Caused by: java.lang.IllegalArgumentException: Username to-be-overwritten-by-vault-value at org.springframework.util.Assert.isTrue(Assert.java:92) ~[spring-core-4.3.9.RELEASE.jar:4.3.9.RELEASE] at com.example.demo.DemoApplication.postConstruct(DemoApplication.java:48) [classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_171] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_171] at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_171] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:311) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:134) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] ... 17 common frames omitted
When i have vault integrated with file system that time path was something like secret\key
it was working fine with this new changes its stop working.