I have these KVs sources store on Consul:
config/books/<key>
config/common/<key>
And in my spring boot app application.yml, I have config it as following:
spring:
application:
name: sampleapp
cloud:
consul:
host: localhost
port: 8500
config:
enabled: true
prefix: config
defaultContext: books
I know that this configuration that I made has pointed the app to read from config/books .
But I can't figure out how can I retrieve the Consul KV config from both config/common and config/books.
It's not really flexible there, but it can be done if you rename your project and use defaultContext as well. Based on the documentation Spring Cloud Consul Config takes next paths:
config/testApp,dev/
config/testApp/
config/application,dev/
config/application/
where testApp - name of your app, application - default context
So with the following configuration it will work
spring:
application:
name: books
cloud:
consul:
host: localhost
port: 8500
config:
enabled: true
prefix: config
defaultContext: common
Logs after running this configuration:
Located property source: CompositePropertySource {name='consul', propertySources=[ConsulPropertySource {name='config/books/'}, ConsulPropertySource {name='config/common/'}]}
Related
I have a config server in github have a structure like this:
-ms_one
|_application.yml
|_application-dev.yml
-ms_two
|_application.yml
|_application-dev.yml
Repo url: My Github Repo
In the project I also follow the same structure:
-configServer
-ms_one
-ms_two
In the application.yml of configServer I have
spring:
application:
name: CONFIGSERVER
profiles:
active: dev
cloud:
config:
server:
git:
uri: <github repo url>
clone-on-start: true
default-label: main
search-paths: {application}
eureka:
client:
fetch-registry: true
register-with-eureka: true
logging:
level:
web: error
In the ms-one service I have in application.yml
spring:
profiles:
active: dev
application:
name: ms-one
config:
import: configserver:http://localhost:8003
Now, I want the config server to fetch the configuration from the folder with the same name as application name and apply the configuration. The problem is the correct configuration is not being fetched. Please help me doing this
I got the idea of setting spring.cloud.config.server.git.search-paths:{application} from the thread How to point spring-cloud-config server to a git folder inside a git repo
I am trying to support K8s ConfigMap API using Spring to handle my externalized configuration. I've been using a configuration service without any issues, so I don't believe it is a cloud-config implementation problem. I am using version 1.0.2.RELEASE of spring-cloud-starter-kubernetes-config.
My ConfigMap consists of two configurations: global (application.yml) and app-specific yaml (myapp.yml). Here is what that looks like:
apiVersion: v1
kind: ConfigMap
metadata:
name: myapp-config
data:
application.yml: |-
kafka:
hosts: kafka:9092
topics:
events: myapp-events
normalized: myapp-normalized
#...
storage:
uri: mongodb://mongo-0.mongo:27017,mongo-1.mongo:27017,mongo-2.mongo:27017
database: do-stuff-db
#...
spring:
cloud:
config:
override-system-properties: false
#...
myapp.yml: |-
myapp:
broadcast-address: 0.0.0.0:666
#...
application.yml seems to work just fine. I can see the configuration values in my application but for whatever reason, myapp.yml does not get set. I can see Spring is successfully grabbing the entire result from the ConfigMap API but it does not do anything with myapp.yml.
Turning on debug logging exposed how Spring is interpreting the ConfigMap result. It is treating the entire myapp.yml section as one property and not its own property source. This explains why the application.yml is taking and not the myapp.yml. Here is what that log looks like (I have truncated the message):
2019-09-04 14:01:37.083 [main] INFO config.PropertySourceBootstrapConfiguration - Located property source: CompositePropertySource {name='composite-configmap', propertySources=[ConfigMapPropertySource#92864491 {name='configmap.myapp-config.default', properties={kafka.hosts=kafka:9092, kafka.topics.events=myapp-events, kafka.topics.normalized=myapp-normalized, myapp.yml=myapp:
bind-address: 0.0.0.0:666
#...
storage.uri: mongodb://mongo-0.mongo:27017,mongo-1.mongo:27017,mongo-2.mongo:27017, storage.database: do-stuff-db}}]}
Do I need to separate these configurations? The examples I've seen from Spring suggest you could consolidate your configuration into a single YAML ConfigMap file. I am stumped.
I just ran jhipster registry and its working fine. It's looking for config files from central-config folder. I want to refactor my config files under folders in the central-config folder itself. That's something that I can achieve running Spring Cloud Config server with a configuration like this:
spring:
cloud:
config:
server:
git:
default-label: develop
uri: file://${user.home}/config-repo
search-paths: employee-service, enterprise-service
How can I achieve such behavior with 'composite thing' in jhipster-registry. For info, this is the bootstrap.yml file from jhipster registry:
# ===================================================================
# Spring Cloud Config bootstrap configuration for the "dev" profile
# In prod profile, properties will be overwriten by the ones defined in bootstrap-prod.yml
# ===================================================================
spring:
application:
name: jhipster-registry
profiles:
active: dev
include: composite
cloud:
config:
server:
bootstrap: true
composite:
- type: native
search-locations: file:./central-config
#search-locations: file://${user.home}/Acensi/isupplier/config-repo
prefix: /config
fail-fast: true
# name of the config server's property source (file.yml) that we want to use
name: jhipster-registry
profile: dev # profile(s) of the property source
label: master # toggle to switch to a different version of the configuration as stored in git
# it can be set to any label, branch or commit of the config source git repository
info:
project:
version: #project.version#
# uncomment to enable encryption features
#encrypt:
# key: my-secret-encryption-key-to-change-in-production
I had the same issue. I added to my application.yml file the following:
spring:
cloud:
config:
server:
bootstrap: true
composite:
- type: native
search-locations: file:./central-config/myFolder
You were very close, hope it helps.
I was upgrading an existing older JHipster Registry to 5.0.1. I was also using the git repo. The problem with the above configurations is that the property is not called search-locations for the git repo it is search-paths. In order to keep everything working as before which was had the search paths specified via an environment variable SPRING_CLOUD_CONFIG_SERVER_GIT_SEARCH-PATHS, I use the following configuration in my prod bootstrap.
bootstrap-prod.yml:
spring:
cloud:
config:
server:
bootstrap: true
composite:
- type: git
uri: git#bitbucket.org:whatever/repo
search-paths: ${spring.cloud.config.server.git.search-paths}
ignore-local-ssh-settings: true
private-key: |
-----BEGIN RSA PRIVATE KEY-----
Currently I'm working in Spring boot micro services project. Consider I have 3 micro services named as A, B, C. Now My project have application.yml file separately for each micro service. Now I want to add one more microservice D, for manage all service property files.
view my config-service structure
eureka.yml(inside config-service) file is:
server:
port: 8761
eureka:
client:
registerWithEureka: false
fetchRegistry: false
server:
waitTimeInMsWhenSyncEmpty: 0
endpoints:
sensitive: false
In eureka-service bootstrap.properties is:
spring:
application:
name: eureka
cloud:
config:
uri: http://localhost:8888
Config service application properties :
spring:
application:
name: config
cloud:
config:
server:
native:
search-locations: classpath:/config/DEVELOP
profiles:
active: native
server:
port: 8888
my config application file is:
#SpringBootApplication
#EnableConfigServer
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
I did the following steps:
start the config-service
start the eureka-service
unfortunately, eureka server getting error.
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
the problem is while running eureka server, its not looking the config file which is inside the config service...
help me to resolve this. or instead of micro service, how can I go with folder?
Thanks # g00glen00b
I am changed config service bootstrap yml as follows :
spring:
application:
name: config
cloud:
config:
server:
native:
searchLocations: classpath:/config/DEVELOP/
profiles:
active: native
server:
port: 8888
Its working fine.
I am working on a Spring Boot Registration Server(Eureka Server).
Currently it is working with below configuration.
Project Name: registration-service
Inside main method: System.setProperty("spring.config.name", "registration-service");
"yml file":
file name: registration-service
content:
eureka:
instance:
hostname: eureka-server
server:
enableSelfPreservation: false
client:
register-with-eureka: false
fetch-registry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
server:
port: 2323 # HTTP (Tomcat) port
spring:
application:
name: eureka-server
With above configuration,application start running on 2323.
But if i change spring.config.name,it does not work,start giving connection refused exception.
why it is happening? even though this spring.config.name is no where used in yml file. Should it be necessarily same as project name? or it is specific to #EnableEurekaServer enabled spring boot application.
And in yml we have to write
spring:
application:
name: eureka-server
though in other spring boot application we give name of current project(here it should be registration-service).why we have to write here eureka-server? I know,I am missing something(or a lot of things).please help me in understanding the missing part.
Spring boot by default looks for file application.yml. If u have different profiles in your application it can also look for application-{profilename}.yml. This is the default convention followed.
spring.config.name property is used to override this default behaviour. When u override this property with register-service then spring boot looks for a file register-service.yml and loads config from that.
So your eureka server url which is given in the register-service.yml file may not be available in the default application.yml file. Hence when u change the value Spring boot may not be avle to find the Eureka server url.
Keep the names unchanged, as much as possible. If u have config file as register-service.yml then keep the spring.config.name=register-service. If you change this value then u need to create the new file with config.name value and then add eureka configuration to that again.