I'm creating a spring boot config client application. I've been referring to various online material - I've already referred to most of it. Im using STS. The application simply doesn't pick up the bootstrap.yml at all. I should see the config from bootstrap file being loaded here - http://localhost:8080/env. I see entries only from application.yml, but not bootstrap. I verified my Config server is running (http://localhost:8888/trial1client/default/master) using correct GIT. Following is my POM
<?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>com.trial</groupId>
<artifactId>trial1client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>trial1client</name>
<description>Trial1 client</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Dalston.SR3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.pivotal.spring.cloud</groupId>
<artifactId>spring-cloud-services-dependencies</artifactId>
<version>1.5.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<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>
</plugins>
</build>
</project>
Comment From: msathe-tech
My application.yml on client side management: security: enabled: false
security: basic: enabled: false
My bootstrap.yml on client side spring: application: name: trial1client cloud: config: uri: http://localhost:8888
Comment From: spencergibb
I'm unsure if this is a spring cloud config problem. Is STS copying bootstrap.yml to your classpath? does it work if you run as a jar?
Comment From: msathe-tech
I see the boostrap.yml in the trial1client\target\classes. If I try mvn clean package it fails I don't have :default for the property. org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'trial1clientApplication': Unsatisfied dependency expressed through field 'message'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'message': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'message' in value "${message}" at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) ~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE]
Following is my bean class - @Component public class Message { @Value("${message}") String message;
public String getMessage() {
return message;
}
}
Comment From: spencergibb
config server isn't available during build and you haven't supplied a default ${message:<defaulthere>}
.
Comment From: msathe-tech
If I add :default for the @value then mvn clean package works (as expected) but it still doesn't solve the problem of boostrap.yml
Comment From: spencergibb
I still don't understand what the bootstrap problem is. Maybe you could provide a sample that reproduces your problem.
Comment From: msathe-tech
Here is the sever code - https://github.com/msathe-tech/trial1
Here is the client code - https://github.com/msathe-tech/trial1client
Comment From: spencergibb
I assume the problem is the client?
Comment From: spencergibb
I'm going to assume it's because of your non-standard project layout.
Comment From: msathe-tech
Yes, the problem is in client. It is not picking up the bootstrap.yml file. Well I just uploaded the files for reference, the project layout is as per STS. No manipulations there. Could you please point out something?
Comment From: spencergibb
Generate a project using start.spring.io
Comment From: msathe-tech
Sure, I'll try that. Are the dependencies and other files ok? Just to make sure thats the only change..Appreciate your help. Thanks!
Comment From: msathe-tech
Well, it continues to disappoint even with start.spring.io. Few things I noticed, I think are causing issue: 1. In the bootstrap.yml it is not able to recognize the spring.cloud property, it shows such a warning: 'Unknown property spring.cloud' 2. Im not able to use @RefreshScope annotation 3. It is still not showing the bootstrap.yml when I access /env. Basically means, it is simply not picking up the config URL
Comment From: spencergibb
1) is an IDE problem, not ours.
You must have some environment problem? Maven proxy?
I created a project with web, actuator and spring-cloud-starter, added bootstrap.properties and have the following in /env
.
"applicationConfig: [classpath:/bootstrap.properties]": {
"management.security.enabled": "false",
"spring.application.name": "demobootstrap"
},
Comment From: msathe-tech
You may be correct, it seems to be STS problem. I downloaded your project and used as is. It still doesn't work. It simply doesn't pick up the bootstrap.properties and so /env returns this - { "timestamp": 1506526557030, "status": 401, "error": "Unauthorized", "message": "Full authentication is required to access this resource.", "path": "/env" }
Comment From: msathe-tech
Well, here is the solution, that worked for me -
1. Add following to POM
<dependencyManagement> <dependencies> <dependency><groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Camden.SR5</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
Don't ask why, just do it because it worked :)
2. Remove following from POM -
<spring-cloud.version>Dalston.SR3</spring-cloud.version>
from <properties>
Something similar to that in in <properties>
Don't ask why, just do it because it worked :)
3. If you are using local file system for GIT then make sure you add '/.git/' to the path e.g.
spring.cloud.config.server.git.uri=C:/stswork/workspace-sts-3.9.0.RELEASE/trial1/src/main/resources/.git/
Sadly, none of the docs suggest to add '.git' in the path URI.
What you need to check out for - 1. Make sure none of your annotations show any warning sign in your IDE, that tiny '!' causes trouble 2. Config server logs - check for message similar to following, to check client specific config file you have created - NativeEnvironmentRepository : Adding property source: file:/C:/...../trial1client.properties 3. Config client logs - check for something similar to following indicating client is able to pull the config
c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://localhost:8888 2017-09-27 15:46:42.443 INFO 9696 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=trial1client, profiles=[default], label=master, version=232a66a62c89105653c00167de79784c44f55844, state=null 2017-09-27 15:46:42.443 INFO 9696 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='configService', propertySources=[MapPropertySource {name='configClient'}, MapPropertySource {name='C:/stswork/workspace-sts-3.9.0.RELEASE/trial1/src/main/resources/.git/trial1client.properties'}]]
Comment From: 129z7k
msathe-tech, thank you )
Comment From: Nataraj2609
The Solution is to add bootstrap dependency in pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
With Spring Cloud 2020, they made a change in how bootstrap works and you have to include a new starter: spring-cloud-starter-bootstrap. Refer https://stackoverflow.com/questions/65063402/why-bootstrap-properties-is-ignored-by-spring-cloud-starter-config