Spring cloud config not apply global configuration - spring-boot

I'm having a problem on spring cloud configuration 2020.0.3, spring boot 2.4.5 for details:
Yaml configuration file is following Multi-profile YAML documents
I have a configuration yaml file on the config server.
my_cofig.yaml
spring:
datasource:
url: "jdbc:mariadb://localhost:3306/default_db"
driver-class-name: org.mariadb.jdbc.Driver
username: my_db
password: 12345
---
spring:
profiles: dev
datasource:
url: "jdbc:mariadb://localhost:3306/dev_db"
I have loaded the config from the config server by browser, it's correct.
But:
When I run Spring application with specific configuration (e.g. dev), Spring application must not apply global configuration variables defined on configuration file from configuration server. It only loads dev's configuration variables.
bootstrap.yaml
server:
port: 8081
spring:
application:
name: auth-service
cloud:
config:
enabled: true
fail-fast: true
allow-override: true
profile: dev
uri: http://localhost:5000
Error detail:
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
Please help me, many thanks!

spring:
profiles:
This does not exist (it was deprecated if I am not mistaken). Please check the reference documentation.
I believe that what you are looking for is the following (reference documentation):
spring:
datasource:
url: "jdbc:mariadb://localhost:3306/default_db"
driver-class-name: org.mariadb.jdbc.Driver
username: my_db
password: 12345
---
spring:
config:
activate:
on-profile: dev
datasource:
url: "jdbc:mariadb://localhost:3306/dev_db"

Finaly, I solved the problem by upgrading spring boot version to 2.5.1
Thanks all

Related

Spring cloud config server setting for logging are never picked up

I have a spring cloud config client and server. I have added some logging-logback settings in the application.yaml of client and I have a different setting under config server. I see that the settings from server are never picked. Can somebody please help. I tried with different versions of spring boot and cloud but observe the same behaviour everywhere.
Please note, I only have issues with the logback.rollingpolicy.max-file-size
All other properties are picked from config-server
My application.yaml in the client
logging:
level:
root: info
file:
path: /Users/abc/demo/src/main/resources/logs
name: application
logback:
rollingpolicy:
max-file-size: 1MB
My bootstrap.yaml
spring:
cloud:
config:
enabled: true
uri: http://localhost:8402
application:
name: demo
My demo.yaml in cloud config server
logging:
level:
root: info
file:
path: /Users/abc/demo/src/main/resources/logs
name: demo
logback:
rollingpolicy:
max-file-size: 500KB

Spring Boot Liquibase doesn't appear to support XML formatted changelog

spring-boot-starter-parent:2.7.5
I have configured the following in my src/main/resources/application.yml file:
spring:
liquibase:
change-log: classpath:/db/changelog/db.changelog-master.xml
---
spring:
config:
activate:
on-profile: prod
datasource:
driver-class-name: org.postgresql.Driver
url: ${DB_URL}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
Additionally, the following resource exists in the project repository:
src/main/resources/db/changelog/db.changelog-master.xml
I also have the following configured in src/test/resources/application.yml:
spring:
config:
activate:
on-profile: test
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
username: sa
password: sa
liquibase:
change-log: classpath:/db/changelog/db.changelog-master.xml
When I try to build this project the build fails with the following error message:
Liquibase failed to start because no changelog could be found at 'classpath:/db/changelog/db.changelog-master.yaml'
Is there some way to configure spring boot to allow an xml based liquibase changelog file? If so, what am I missing? Or does it only support the yaml format?
Your configurations seems valid, but some configuration still points to classpath:/db/changelog/db.changelog-master.yaml (based by on provided error message)
If there is no some typo, than may be you should look for this property in some other configuration (.properties files, command line arguments and other, see doc for all possible ways)

Spring-Cloud-Config not getting properties

I cannot Create properties as I get this error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configClient': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'user.role' in value "${user.role}"
I am following this tutorial:
http://www.baeldung.com/spring-cloud-configuration
I am using
#Value("${user.role}")
and
#Value("${user.role:}")
does not fetch any information.
I have the same issue that you when I tried the tutorial. It seems the client can't achieve the server to resolve the property 'user.role', in my case, the error was the wrong property:
spring.application.name: config-client
You can check the configurations of the server, If you can access your github repo with configs. With server running, like this:
curl http://root:s3cr3t#localhost:9090/config-client/development/master [13:26:43]
{"name":"config-client","profiles":["development"],"label":"master","version":"80d048de5faa3314429a1fce1645917786da28d6","state":null,"propertySources":[{"name":"https://gitlab.com/marcosnasp/spring-config-baeldung-tutorial.git/config-client-development.properties","source":{"user.role":"Developer"}}]}%
I used the the yml config for both, and a different port for the server 9090, the client port by default, since I have not configured in application.properties is the 8080, client and server, at looks like:
the client config:
bootstrap.yml
spring:
application:
name: config-client
profiles:
active: development
cloud:
config:
uri: http://localhost:9090
username: root
password: s3cr3t
fail-fast: true
the server config:
bootstrap.yml
spring:
application:
name: delivery-config-server
encrypt:
key-store:
location: classpath:/config-server.jks
password: my-s70r3-s3cr3t
alias: config-server-key
secret: my-k34-s3cr3t
application.yml:
server:
port: 9090
spring:
cloud:
config:
server:
git:
uri: https://gitlab.com/marcosnasp/spring-config-baeldung-tutorial.git
timeout: 10
clone-on-start: true
security:
user:
name: root
password: s3cr3t

Spring Cloud Config Server not enforcing BASIC Authentication when running main()

I have configured a Spring Cloud Config server to force BASIC authentication and here is my application.yml file:
# Config Repo:
spring:
cloud:
config:
server:
git:
uri: file:///${HOME}/microservices_config_repo
# Show sensitive information for endpoints:
endpoints:
sensitive: true
# Security for endpoints:
management:
security:
enabled: true
security:
user:
name: user1
password: changeme
My issue I am having is that when I start the server up as:
mvn spring-boot:run
The server endpoints FORCE BASIC Authentication.
But when I start the Application.main() method, BASIC Authentication is enabled, but NOT enforced.
Meaning I can access configuration on:
http://localhost:8888/client-config
and
http://user1:changeme#localhost:8888/client-config
Can anyone help me understand why this is occuring and how to enforce BASIC Authentication while running the Application.main(), and not just through the Maven spring-boot plugin?
Note, when I use maven to package the app into a jar, then run the generated jar, BASIC Authentication is enforced, but still not through the IDE running just the Application.main directly.
Maybe the format the oy Yaml for example to me seems works like this:
server:
port:9999
spring:
application:
name: config-server-sample
cloud:
config:
name: ${spring.application.name}
fail-fast: true
server:
git:
uri: url
username: xx
password: zz
default-label: master
basedir: '${user.home}/${spring.application.name}/default'
timeout: 10
clone-on-start: true
force-pull: true
security:
basic:
enabled: true
path: /**
ignored: /health**,/info**,/metrics**,/trace**
user:
name: admin
password: tupassword

spring boot yaml profile names resolution

I have multimodule maven project in which I have one common part which I want to share between applications.
In common module I'm defining the configuration for liquibase and db connection. For this I have 2 profiles common-prod and common-dev located in application.yaml.
spring:
profiles: common-prod
# POSTGRE
datasource:
url: ${DATABASE_URL:jdbc:postgresql://localhost:5432/dbname}
driver-class-name: org.postgresql.Driver
username: pguser
password: pguser
jpa:
database-platform: org.hibernate.dialect.PostgreSQLDialect
hibernate:
ddl-auto: none
properties:
hibernate.default_schema: public
#LIQUIBASE
liquibase:
enabled: true
change-log: /db/changelog/db-changelog-master.xml
drop-first: false
---
spring:
profiles: common-dev
# POSTGRE
datasource:
url: ${DATABASE_URL:jdbc:postgresql://localhost:5432/dbname-dev}
username: pguserdev
password: pguserdev
#LIQUIBASE
liquibase:
enabled: true
drop-first: true
now in web application I want to define some additional properties. But when I include them in application.yaml (in web module) I think it overrides the application.yaml from common module.
So I need to
rename the application.yaml from common to something like application-common.yaml
rename the application.yaml in application to something like application-web.yaml
if I rename the common module's yaml file am I able to reference the profiles from within this file? eg something like -Dspring.profiles.active=common-common-prod or I need to separate this profiles to separate yaml files?
If I rename web modules config file to application-web.yaml I must allways include the web profile. I can live with that, but it would be simpler to include the profiles in application.yaml and don't care about command line arguments.

Resources