We have a springboot app which is using Consul for properties management. We have a boolean property in Consul which is set to false.
While starting the app, we have the same property set at command line argument as true.
What I observed is this property is taking the value from Consul and not from the command line argument.
What is the order or precedence here?
Related
I am having a use case to read some specific env variable which are set at system level based on the queried to database and want to refer into another spring boot app
I am able to set it through System.setProperty("XYZ", "123") but when I refer it into another spring boot app it is returning null with System.getProperty call..
And both application is running into same container or JVM or instance...
Please, help...
Thanks,
You can't use System.setProperty because this is only visible in current Java process
You can't use System.setEnv because this is also only visible in the current process
You could write a file that the other process is reading or you could provide a REST endpoint so that one app can call the app.
Currently spring boot seems to support only classpath based logging configuration.
It also ignores any configuration passed as vm argument as follows.
-Dlog4j.configurationFile=/opt/xyz/log4j2-prod.xml
How can we have different log4j2 configuration based on different environment, considering classpath for all environment remains same.
What about set the properties: logging.config=classpath:log4j2-dev-spring.xml in each application-{profile}.properties that you have. Can use like this too: logging.config=${ENV_VAR}
You should use the following param
-Dlogging.config='/path/to/log4j2.xml'
I would like to pass the ID of an object to a variable when starting a Task in Spring Cloud Dataflow. I know that it can be done with arguments or parameters, but I don't know how to handle these arguments or parameters in Java code so I can take over this value. Could you please indicate how this could be done?
In the context of Spring Cloud Data Flow, you can pass arguments or properties to your task application.
The arguments you pass for the Spring Cloud Task application are the command line arguments for the task application itself. You need to qualify the arguments as the command line arguments for your application.
The properties you pass for the Spring Cloud Task application are the application configuration properties or task deployer properties. They have to use the prefix app, deployer or scheduler.
For instance, for the out-of-the-box timestamp task application, you can see how arguments and properties can be used in the following example:
Register out-of-the-box task applications
Create timestamp task:
dataflow:>task create a1 --definition "timestamp"
Launch the task with arguments and properties
dataflow:>task launch a1 --arguments "--spring.main.banner-mode=off" --properties "app.timestamp.format=YYYY/DD/MM"
In the above case, the command line argument --spring.main.banner-mode=off is passed to the timestamp application while the timestamp application's property format is passed to the task application.
I have inherited a java Spring Boot project and I'm new to most java configurations. When I run this application in debug mode the first argument passed to my application as args[0] is --spring.output.ansi.enabled=always. I have searched my project files but cannot see where this might be configured to turn off, that is I do not want it passed in as an argument. I am using the Spring STS 3.9.1 IDE.
In the Spring STS IDE the Debug Configuration has an option ANSI console output which was checked. Unchecking stopped the argument being passed.
Under Debug Configuration, uncheck the field highlighted in Red.
All previous answers are correct. Nevertheless, here another alternative to configure Ansi output, even though it does not answer the original question (remember, args[0] had a value): the environment variable SPRING_OUTPUT_ANSI_ENABLED=always could be set, either in the STS/Eclipse run/debug configuration (tab Environment), or otherwise for your account, or globally on your machine.
By the way, any Spring Boot configuration property can be configured via environment variables:
either in a SPRING_APPLICATION_JSON environment variable,
or with Binding from Environment Variables
You can put any Spring Boot configuration properties into your application.properties (see here).
Or you can use any of the other mechanisms to externalize your configuration properties (see here).
We're using Spring Cloud Angel.SR6 with Netflix Eureka and Spring Config Server. One of our microservices is a distributed system that uses Eureka as a discovery mechanism to find peers. In order to start up the system in the correct way when multiple instances are started in parallel, we would like to know which node started first. The application information in Eureka contains a few different timestamps, but they change when the Eureka client updates the status so it seems that we can't rely on them.
Our idea now is to have the application register its own boot timestamp in the Eureka metadataMap which we have been able to accomplish using the EurekaInstanceConfigBean. With this approach however, the timestamp is added too late in the process. The instances initially appear in Eureka without the timestamp, which is not good enough for us (and even if it would be, it takes to long to be a nice solution).
What we are trying to do instead is to get the timestamp included in the initial Eureka registration. Properties declared in bootstrap.properties are included, so if we could somehow get the timestamp in here everything would work:
eureka.instance.metadataMap.bootTimestamp=<here we want the timestamp>
We have tried to add a custom PropertySourceLocator using the approach mentioned in the Spring Cloud Documentation, but still no luck. The initial Eureka registration happens before the the PropertySourceLocator is initialized which again is too late.
How can we get the boot timestamp into the environment before the initial Eureka registration so the application never appears in Eureka without a timestamp?
We found a not altogether satisfying work-around, so I'm posting this in somebody finds it useful. By passing a timestamp in an environment variable or a system property we are able to include it in the initial registration of metadata in Eureka.
Command line (assuming Linux/bash):
BOOT_TIMESTAMP=$(date +%s%3N) java ...
bootstrap.properties:
eureka.instance.metadataMap.bootTimestamp=${boot.timestamp:0}
you can set an evn Property by using System.setProperty when the application gets started. and after that you can use it through the property file like below.
public static void main(String[] args) {
System.setProperty("APP_TIMESTAMP", String.valueOf(System.currentTimeMillis())); //this is the line to set the time that the application gets started.
SpringApplication.run(UseServiceApplication.class, args);
}
usage of env value in property file (i have used yml file here.)
eureka:
instance:
metadata-map:
timestamp: ${APP_TIMESTAMP}