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
Related
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
Spring Config-Client is in initial startup so It would not have cached the data from config server,
if either Config-Server or GIT or both are down - what can be done in that case to get the data and maintain service availability.
You can use the following (basedir) element of yml file with following hierarchy.
The "basedir" element will cache your config data whenever application restarts and keep that on the specified path which is specified against this key as a value.
Example :
basedir : C:\POC_CONFIG_SERVER\config-repo-am
server:
port: 8888
spring:
application:
name: cloud-config-server
cloud:
config:
server:
git:
uri: ${uri}
force-pull: true
skip-ssl-validation: true
skipSslValidation: true
username: ${username}
password: '${password}'
default-label: master
basedir: ${basedir}
I would like to read some configurations from multiple git repositories, something like:
spring:
profiles:
active: base, app1, app2
cloud:
config:
server:
base:
uri: http://${GIT_HOST}/base/base.git
username: ${GIT_USERNAME}
password: ${GIT_PASSWORD}
app1:
uri: http://${GIT_HOST}/group1/app1.git
username: ${GIT_USERNAME}
password: ${GIT_PASSWORD}
app2:
uri: http://${GIT_HOST}/group2/app2.git
username: ${GIT_USERNAME}
password: ${GIT_PASSWORD}
At startup I see the following exception:
Caused by: java.lang.IllegalStateException: You need to configure a uri for the git repository
The documentation shows an example using two different repos, git and svn. Can't we use multiple repos of the same kind?
Due to the link of document you said, the svn and git after server is the type, not profile. So you cannot use base, app1, app2.
But in your case, I think you can use this kind of config: document link.
spring:
cloud:
config:
server:
git:
uri: https://git/common/config-repo.git
repos:
team-a:
pattern: team-a-*
cloneOnStart: true
uri: http://git/team-a/config-repo.git
team-b:
pattern: team-b-*
cloneOnStart: false
uri: http://git/team-b/config-repo.git
team-c:
pattern: team-c-*
uri: http://git/team-a/config-repo.git
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
I'm trying to setup my application with multiple repositories - a local file based one for development/testing purpose and a remote git repo for production.
I am using the following yaml for this purpose -
spring:
application:
name: localRepoConfig
cloud:
config:
server:
git:
uri: https://github.com/spring-cloud-samples/config-repo
repos:
development:
pattern:
- '*/development'
- '*/staging'
uri: https://github.com/development/config-repo
native:
searchLocations: classpath:/config
server:
port: 8888
This is not working however, the following works for the local repo -
spring:
application:
name: localRepoConfig
profiles:
active: native
cloud:
config:
server:
native:
searchLocations: classpath:/config
server:
port: 8888
I have not been able to make the two repositories function, after following the Spring documentation and a few posts here.
Would greatly appreciate if someone can point me in the right direction.
I got this working with the following config in bootstrap.yml -
spring:
application:
name: localRepoConfig
profiles:
active: native
cloud:
config:
server:
native:
searchLocations: classpath:/config
server:
port: 8888
---
spring:
profiles: development
cloud:
config:
server:
git:
uri: https://github.com/spring-cloud-samples/config-repo
server:
port: 8989
I am able to switch between the native and development profiles now.
The following guide was quite helpful -
kubecloud.io/guide-spring-cloud-config/
Based on the documentation on Spring Cloud Config it sounds like native and git are mutually exclusive and that you can't use both for a single config server.