Spring Cloud Vault: Token (spring.cloud.vault.token) must not be empty - spring-boot

Hi everyone
I created a program to test the vault with start.spring.io. And I configure the vault in the bootstap.properties file like this:
spring.application.name=vault-test
spring.cloud.vault.uri=http://localhost:8200
spring.cloud.vault.token=MY_ROOT_TOKEN
Here is my pom.xml configuration:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>15</java.version>
<spring-cloud.version>2020.0.0</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-vault-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
Also, the vault development server is pre-set up with the following command:
vault server -dev
But when I run the program, it has the following error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vaultTemplate' defined in class path resource [org/springframework/cloud/vault/config/VaultAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.vault.core.VaultTemplate]: Factory method 'vaultTemplate' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'vaultSessionManager' defined in class path resource [org/springframework/cloud/vault/config/VaultAutoConfiguration.class]: Unsatisfied dependency expressed through method 'vaultSessionManager' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientAuthentication' defined in class path resource [org/springframework/cloud/vault/config/VaultAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.vault.authentication.ClientAuthentication]: Factory method 'clientAuthentication' threw exception; nested exception is java.lang.IllegalArgumentException: Token (spring.cloud.vault.token) must not be empty
But the vault token is set in the bootstrap.properties file !. But the strangest thing for me is that when I set the token in the application.properties file, I will not have an error! I know the bootstrap.properties file is called before the application properties file is called, and the token must be set in it, but why does the vault not notice it?

With Spring Boot 2.4, the bootstrap context initialization(bootstrap.yml, bootstrap.properties) of property sources is deprecated.
Please refer below:
https://stackoverflow.com/a/65009480

You seem to be missing the spring-cloud-starter dependency ( which should be added if you select the Cloud Bootstrap dependency on start.spring.io .
Just add the following dependency in your pom.xml file :
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>

Related

Upgrading Spring Boot to 2.5.9 and getting FileNotFoundException: class path ...../boot/actuate/health/HealthAggregator.class] cannot be opened

I am getting a FileNotFoundException during Spring Boot initiation for org/springframework/boot/actuate/health/HealthAggregator.class. This seem related to https://github.com/spring-projects/spring-boot/issues/19860 but that was back in 2.2.
I have tried different versions of Spring Boot, 2.5.9 etc, different versions of Spring Cloud, etc.
Any thoughts on how I can resolved this?
Key parts of my POM
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
..
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>2021.0.0</spring-cloud.version>
</properties>
..
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
..
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-client-config</artifactId>
<version>2.1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
The error:
is 2022-01-25 20:16:20 WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.xxxxx.vms.yyyyy]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/boot/actuate/health/HealthAggregator.class] cannot be opened because it does not exist 2022-01-25 20:16:20 ERROR o.s.boot.SpringApplication - Application run failed

Zipkin with Spring Boot 2.2 and Hoxton Cloud

I wanted to update my project Zipkin setup to Spring Boot 2.2.2.RELEASE and Spring Cloud Hoxton.RELEASE but it looks like simple jars update is not enough.
I thought the old setup (it was working fine for Spring Boot 2.1.5.RELEASE and Greenwich.SR2) would also work for Boot 2.2.2.RELEASE and Hoxton.RELEASE but it appears I still miss something here.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/>
</parent>
<properties>
...
<spring-cloud.version>Hoxton.RELEASE</spring-cloud.version>
<!-- <zipkin.version>2.12.9</zipkin.version> does not work either-->
<zipkin.version>2.11.8</zipkin.version>
...
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-server</artifactId>
<version>${zipkin.version}</version>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
<version>${zipkin.version}</version>
<scope>runtime</scope>
</dependency>
...
</dependencies>
I'm getting the following exception (java.lang.NoClassDefFoundError: zipkin2
/internal/Buffer$Writer):
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcMetricsFilter' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/We
bMvcMetricsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'webMvcMetricsFilter' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pr
ometheusMeterRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfiguration.class]: Initialization of bean failed; nested exception is or
g.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'zipkin2.server.internal.ZipkinServerConfiguration': Unsatisfied dependency expressed through field 'httpQuery'; nested exception is org
.springframework.beans.factory.BeanCreationException: Error creating bean with name 'zipkin2.server.internal.ZipkinQueryApiV2': Bean instantiation via constructor failed; nested exception is java.lang.NoClassDefFoundError: zipkin2
/internal/Buffer$Writer
It's a version problem. Zipkin officially recommends use zipkin-server instate of customer server after spring-boot 2.x.
For me, the 2.12.9 library works well under spring-boot 2.1.8.RELEASE with spring-cloud Greenwich.SR6

When move from derby to mysql base there is config-error in spring-boot application?

I am creating application on spring-boot+jpa+web+tomcat(, so there is pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>myApp</groupId>
<artifactId>myApp</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
<spring.boot.version>2.0.4.RELEASE</spring.boot.version>
</properties>
<dependencies>
<!--Spring-boot dependencies-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.boot.version}</version>
<scope>test</scope>
</dependency>
<!--deploy on remote tomcat-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
<!-- DATABASE-->
<!--In-memory database-->
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.14.2.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<finalName>myAppFileName</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
With this pom application started ok.
But, when I try to subsitute derby on mySql removed old dependency and add new
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
and added application.properties
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/mydb
spring.datasource.username=user
spring.datasource.password=111111
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
There is error message:
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
11-Sep-2018 11:34:00.714 SEVERE [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
... 42 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
... 73 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver clas
... 86 more
Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
... 87 more
11-Sep-2018 11:34:00.752 SEVERE [RMI TCP Connection(3)-127.0.0.1] org.apache.tomcat.util.modeler.BaseModelMBean.invoke Exception invoking method manageApp
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
11-Sep-2018 11:34:00.753 SEVERE [RMI TCP Connection(3)-127.0.0.1] org.apache.tomcat.util.modeler.BaseModelMBean.invoke Exception invoking method createStandardContext
javax.management.RuntimeOperationsException: Exception invoking method manageApp
Caused by: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
... 33 more
Is there some addition customizations for spring-boot I need?
mySql mydb base is exists, but there are no any tables in it.
The reason was in application.properties. I named it by application.propereties

Spring config server not starting with keystore

trying to boot spring cloud config server with a keystore but am getting the following on startup:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'encryptionBootstrapConfiguration': Unsatisfied dependency expressed through field 'encryptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'textEncryptor' defined in org.springframework.cloud.bootstrap.encrypt.EncryptionBootstrapConfiguration$RsaEncryptionConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.crypto.encrypt.TextEncryptor]: Factory method 'textEncryptor' threw exception; nested exception is java.lang.NullPointerException
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'textEncryptor' defined in org.springframework.cloud.bootstrap.encrypt.EncryptionBootstrapConfiguration$RsaEncryptionConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.crypto.encrypt.TextEncryptor]: Factory method 'textEncryptor' threw exception; nested exception is java.lang.NullPointerException
Caused by: java.lang.NullPointerException: null
at org.springframework.cloud.context.encrypt.EncryptorFactory.create(EncryptorFactory.java:34) ~[spring-cloud-context-1.1.9.RELEASE.jar:1.1.9.RELEASE]
The following options are used to start the component:
--spring.cloud.config.server.git.uri=http://mygit.com/alexander.lovett/service-discovery-demo.git
--spring.cloud.config.server.git.searchPaths=Software/config
--spring.rabbitmq.host=spring-bus
--management.security.enabled=false
--encrypt.keystore.location=file://C:/Users/607567487/BTTV/workspace/service-discovery-demo/Software/config-serverserver.jks
--encrypt.keystore.secret=changeme
--encrypt.keystore.password=letmein
--encrypt.keystore.alias=mytestkey
I've tried the location as file://C:/.../server.jks file:C:/.../server.jks and even put the jks on the classpath and tried classpath:server.jks
But still get the same error regardless.
My dependencies:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-monitor</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.8.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Simple fix...
the properties should be encrypt.key-store.* not encrypt.keystore.*
I had the same issue, but a different cause. Here is a short description. In a nutshell, the problem was caused by ENCRYPT_KEY environment variable that triggered textEncryptor bean autoconfig with malformed KeyProperties. Spring failed to populate KeyProperties from the environment variable ENCRYPT_KEY causing NullPointerException. If encryption key is provided as system property -Dencrypt.key=123 then spring will have no problems configuring textEncryptor bean.

app fails to start when sleuth and zipkin are added

I have a Spring Boot app that I'm updating to 1.5.1. It works great, until I add Sleuth and Zipkin to classpath
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
when these lines are present, I get
2017-02-22 22:33:05.331 ERROR [chathub-api,,,] 7581 --- [ main] o.s.boot.SpringApplication : Application startup failed
java.lang.NoClassDefFoundError: org/springframework/boot/context/embedded/FilterRegistrationBean
This is my dep. management
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
I tried change to Dalston
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.BUILD-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/libs-snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
but the errors get even stranger
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method envInfoContributor in org.springframework.boot.actuate.autoconfigure.InfoContributorAutoConfiguration required a bean of type 'org.springframework.core.env.ConfigurableEnvironment' that could not be found.
and
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'traceWebFilter' defined in class path resource [org/springframework/cloud/sleuth/instrument/web/TraceWebAutoConfiguration.class]: Unsatisfied dependency expressed through method 'traceWebFilter' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'traceFilter' defined in class path resource [org/springframework/cloud/sleuth/instrument/web/TraceWebAutoConfiguration.class]: Unsatisfied dependency expressed through method 'traceFilter' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sleuthTracer' defined in class path resource [org/springframework/cloud/sleuth/autoconfig/TraceAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sleuthTracer' parameter 4; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'zipkinSpanListener' defined in class path resource [org/springframework/cloud/sleuth/zipkin/ZipkinAutoConfiguration.class]: Unsatisfied dependency expressed through method 'zipkinSpanListener' parameter 2; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.core.env.Environment' available: expected at least 1 bean which qualifies as autowire candidate. Dependenc...
am I missing something I haven't noticed yet?
I can't explain the error that you got with Dalston.BUILD-SNAPSHOT, but the error with Camden.SR4 is because it's not compatible with Spring Boot 1.5. I'd recommend upgrading to Camden.SR5 which is compatible with Spring Boot 1.5.
Even I got this error while setting up my project. I was using Spring boot 1.5.8 with the Brixton.SR6 release. However, when I consulted the site http://projects.spring.io/spring-cloud/ I got to know the issue and I updated my dependency to Dalston.SR4 and then the application started working.

Resources