I have a spring cloud project. There are config server (config-srv), eureka server (eureka-srv) and some other service with business logic, let's call it main service (main-srv).
I'm packaging them into jars and run one by one. My apps get their properties from a file in the same directory with jars.
So, I'm setting properties to config-srv through "application-native.properties".
But if i want to change config-srv url (for example, i want http://localhost:9999), how can i share this url for all micro-services before they will boot ? I'm trying to share this url in "application-default.properties" but it makes no effect.
You can put the Spring Cloud Config server details in bootstrap.properties file in each microservices.
spring.application.name=microserviceName
spring.profiles.active=dev
spring.cloud.config.uri=http://localhost:9999
spring.cloud.config.username=your_username
spring.cloud.config.password=your_password
Go through the link to have more detail about spring cloud config
https://howtodoinjava.com/spring-cloud/spring-cloud-config-server-git/
Related
I'm working with spring cloud config server, and my need is to create a configuration file for each stage prod test and dev, I already created 4 yml file application.yml for the default profile, application-{profiles} for each profile, so my question is how to load the specific configuration through the environment variable and run the config server on each profile configuration and port , I already created a bootstrap.yml but I can't solve the issue.
I will be very thankful if someone can guide throught the steps to achieve my need.
You don't need to start Spring Cloud Config Server with different profiles and on different port per environment. You can have one Config Server that manages the configurations for all environments. In your client's bootstrap.yml you will need to provide the URL of your Config Server as follows:
spring:
cloud:
config:
uri: http://your-config-server
When you run your client application with a particular profile (e.g. via an environment variable spring_profiles_active=dev), Spring Cloud Config Client will fetch the configuration properties from Config Server for the targeted profile.
I recommend to review at least the Quick Start section of the Spring Cloud Config documentation and try the examples provides there.
I've a setup with Spring Cloud Config Server and Client as described in the response here. The next thing I'm trying to do is load the properties from application.properties in the client when the service starts. Once I call /actuator/refresh I would like to load it from the Config Server. Is this even possible? Thanks!
What is bootstrap yaml in spring boot?
And could you advise where I can use it?
bootstrap.yml is used in spring cloud
It is starting before application.yml
It is almost use with spring cloud config server
Spring cloud config server is server which is used to externilize your application configuration.
And when starting your application bootstrap.yml will take the configuration from spring cloud config server.
It also can use encrypting and decrypting some information by :
'{cipher}someyour encoded text'
and server will decode it while pulling the configurations
But you need to create jks
You can reach the documentation for more information about spring cloud :
https://spring.io/guides/gs/centralized-configuration/
Configuration files in spring boot will be loaded in such order:
1. src/main/resources/bootstrap.yml
2. src/main/resources/application.yml
3. config/application.yml
I am following this video to learn micro-services.
My questions is: Can micro-services read configuration from config service through Eureka, or they can only read configurations directly from config server ?
I am trying to configure and make a client read its configuration from eureka but with no success.
You can use the following option in your bootstrap.yml
spring.cloud.config.discovery.enabled=true
And you also need to specify the the service id of your config service.
spring.cloud.config.discovery.serviceId=xxxx
serviceId is usually the the application name.
If you do like above, your microservivces will try to find the address of config server via discovery service.
You can find more details here.
I'm having a problem with how to use just Netflix Archaius to work as a config server for multiple Spring Boot microservices. Previously when I applied Eureka and Spring Cloud Config Server in my multiple-services project built with Spring Boot, each microservie would get its own .properties file from the Spring Cloud Config server through the discovery function of the Eureka service. But now I need to change the Spring Cloud Config Server into a Netflix Archaius service, from which the Spring Boot microservices will get .properties file, i have no idea about how to achieve it. Is there any good idea for my reference? Thanks in advance.
Finally I gave up using Netflix Archaius to pull properties file for microservices. Instead, I wrote down required key-value-pair properties into the application.properties of each springboot microservice. Since all the springboot microservices will be deployed in the DCOS platform in the form of docker containers, some inconstant properties were configured into the marathon deployment scripts, which could be populated into the springboot applet. In this way I managed to configure the key-value-pair properties from the outside instead of being hardcoded in the program codes.