Bootstrap.Yml Not Loading in Spring Boot 2

bootstrap.yml not loading for Spring Boot 2

The bootstrap.yml (or .properties) file is only used, if you use any of the Spring Cloud Starter modules. This is used to specify the spring cloud config server location for bootstrapping a minimal application context that will gather the application properties from the config server and then create a child context with these properties to start the real application.
If you do not make use of the Spring Cloud config capabilities, the way to go is to use the application.yml or .properties files for your application.

Spring boot is not loading bootstrap.properties file

I took a look at your pom file, you are not creating any springboot cloud project because typically you will find a corresponding Spring Cloud BOM version in pom.xml if you used https://start.spring.io/, like so

  <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>

That's why the bootstrap file is being dismissed.
Here is a number of spring cloud projects you can use.

You can start by:

A. creating a spring cloud config server project

B. Make your actual project the spring cloud config client
here is the official tutorial

Sorry If I'm not understanding your question properly, but if you are already created a springcloud project, one possible issue is the version...

Here similar issue was raised on Stack Overflow.

bootstrap.yml configuration not processed anymore with Spring Cloud 2020.0

As pointed put by Nicoll, With Spring Cloud Vault 3.0 and Spring Boot 2.4, the bootstrap context initialization (bootstrap.yml, bootstrap.properties) of property sources was deprecated. This can be fixed in one of the 2 ways

  1. Use Spring Boot 2.4.0 Config Data API to import configuration from Vault (Preferred)
  2. Legacy Processing: Enable the bootstrap context either by setting the configuration property spring.cloud.bootstrap.enabled=true or by including the dependency
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

1. Use Spring Boot 2.4.0 Config Data API (Preferred)

Move bootstrap.yml configuration to application.yml and updated file looks like below

application.yml

spring:
cloud:
vault:
authentication: APPROLE
app-role:
role-id: ${role-id}
secret-id: ${secret-id}
role: pres-read
app-role-path: approle
uri: ${vault-server}
connection-timeout: 5000
read-timeout: 15000
config:
import: vault://secret/app/pres/

And define individual profiles as shown below. Add spring.config.import: vault://secret/app/pres/demo property.

application-demo.yml

## Server Properties
server:
port: 8081

spring:
config:
import: vault://secret/app/pres/demo
datasource:
username: ${pres.db.username}
password: ${pres.db.password}
url: ${pres.db.url}
driver-class-name: com.mysql.cj.jdbc.Driver

Repeat the same process for all profiles like dev, test, qc, staging and prod.

2. Legacy Processing:

Add the following dependency if you still want to use bootstrap.yml

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

to the project. The issue will be resolved.

See Spring Cloud Vault docs for more information

Config Client is not working in Spring boot

2020.0.0 Spring Cloud Config does not support bootstrap file.

For a workaround use bootstrap.{yml|properties} and add a dependency on
spring-cloud-starter-bootstrap to restore the old behavior.

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

More information:

https://github.com/spring-cloud/spring-cloud-release/wiki/Spring-Cloud-2020.0-Release-Notes#breaking-changes

Spring Boot: Load common config application properties file using bootstrap.yml

The configuration in commonConfig is not being loaded because you are not indicating to Spring that it should load that profile/config, because you are activating only the dev profile - and the configuration for that profile is the one which is being loaded:

---
spring
profiles: dev

In addition to the good solutions proposed by @akozintsov in his/her answer, if you need to include certain common configuration in different environments or profiles, let's say dev, qa or prod, you can use the spring.profiles.include configuration property and include, as a comma separated list of values, if using properties files, or as a list, if using yaml, the different common profiles and corresponding configurations you need to.

In your example, in helloApp-dev.properties you need to include the following information within the rest of your configuration:

spring.profiles.include=commonConfig

These related SO question and this article could be of help as well.

Why bootstrap.properties is ignored by spring-cloud-starter-config?

With Spring Cloud 2020, they made a change in how bootstrap works and you have to include a new starter: spring-cloud-starter-bootstrap.



Related Topics



Leave a reply



Submit