spring boot config - property file order - spring-boot

I am using spring boot config. My configurations are located in one folder in git.
The folder structure is as follows
application.yml
registry.yml
I have the following property defined in application.yml
registry:
server:
port:${REGISTRY_PORT:8761}
host:${REGISTRY_HOST:localhost}
and than i have the following property defined in registry.yml
server:
port: ${registry.server.port}
I get the following exception during spring boot start up. I feel registy.yml file is loaded first. Any way i can make application.yml file loaded first.
java.lang.IllegalArgumentException: Could not resolve placeholder 'registry.server.port' in value "${registry.server.port}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:172) ~[spring-core-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124) ~[spring-core-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:237) ~[spring-core-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:211) ~[spring-core-5.1.0.RELEASE.jar:5.1.0.RELEASE]

Related

Config data location 'configserver:http://localhost:8888/' does not exist

My config server is running on localhost:8888 but when i try to fetch configs from my config server ,its shows this error
Config data location 'configserver:http://localhost:8888/' does not exist
Action:
Check that the value 'configserver:http://localhost:8888/' at class path resource
[application.properties] - 2:22 is correct, or prefix it with 'optional:'
my other microservice has this application.properties
spring.application.name=limits-service
spring.config.import=configserver:http://localhost:8888/
spring.profiles.active=dev
This worked for me after removing text configserver from
spring.config.import properties
Before
spring.config.import=configserver:http://localhost:8888/
After
spring.config.import=http://localhost:8888/

getting Could not resolve placeholder while reading yml values in spring boot

I'm using spring boot and using this value in my application.yml
config:
username: abc
password: xyz
In my class, I'm utilizing it this way -
#Value("${config.username}")
private String username;
I'm getting the following error -
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'config.username' in value "${config.username}"
However if I use this in my application.yml file, it works. Can you please tell me what I'm doing wrong here?
config.username: abc
config.password: xyz
check your placeholder is Tab or Space ? make sure no Tab in your yml file.
was facing the same problem when trying to read from application.yml file instead of application.properties file. maven clean & then maven install resolved the issue for me.

Spring Boot duplicates logs

In my project, Spring Boot by default writes logs into logs.log. I need to set the logs location. I've added into my configuration yaml this config:
logging:
file: logs-directory/logs-file.log
After that, Spring Boot logs into default file "logs.log" and the same content into defined "logs-directory/logs-file.log" file. How to switch off default location?
Spring Boot upgrade to 2.5.2 resolved my problem.
Current log configuration in the application.yaml:
logging:
level:
root: info
org.springframework.web: error
org.hibernate: error
file:
name: logs/example-app.log

Spring cloud's config server plain text api with SVN and a default label

I have spring boot 2 app that acts as a config server with the following properties. Notice in particularly the "default-label" properties which is the empty string because we check out directly the folder that contains the files, and not some parent branch/folder.
spring:
application:
name: config-server
profiles:
include: subversion
cloud:
config:
server:
svn:
uri: https://...somesvnrepo.../project/trunk/config
username: fake
password: notreal
default-label:
basedir: C:\Users\John\Documents\Application\configserver_tmp
The contents of /trunk/config is straigthforward. There ae no subdirectories and just these files:
application.yml
application-dev.yml
myservice.yml
myservice-dev.yml
logback.xml
Serving the yml files works fine, but getting the logback.xml file using the "plain text api" not work at all.
Doing localhost:8888/appname/default/master/logback.xml gives the error "no label master found" which is true, I don't have that label. Any other combination of paths by omitting profiles or labels results in a 404 all the way up to just calling localhost:8888/logback.xml. Adding the ?useDefaultLabel request parameter makes no difference. Actually I don't understand the purpose of the appname, profile and label part of the url when the context is to get a plain text file that is not bound to any specific application, profile or label.
I found similar questions on the internet but they mention updating their spring boot version and then it worked for them. I'm already at the latest spring boot version (2.1.3-release).
Is this because I use SVN? Or because of of the default-label being empty?

Spring Boot yaml configuration doesn't load second key

I'm trying to create a config file in yaml for my Spring Boot project.
For a test I just setup some values:
user:
test: hello
Now I'm trying to get the information of user.test, but I get the error message Could not resolve placeholder 'user.test' in value "${user.test}"
The strange thing is, that if my config files just has user.test: hello, then everything works fine.
Is there something that I have to setup before to work with yml files as properties?

Resources