I'm using camel in spring boot. I want to save file in dynamic name. Example using current timestamp for file name like "Prefix-20170612115230.xml". I can do that if I hard code it like from(FTP).marshal().to("file:tmp/outbound?fileName=Prefix-${date:now:yyyyMMddHHmmss}.xml").
But if I add this value to application.properties as outbound.ftp.location=file:tmp/outbound?fileName=CA-RP-na-${date:now:yyyyMMddHHmmss}.xml and using this value in route as from(FTP).marshal().to("{{outbound.ftp.location}}"), then the file name is something like Prefix-now:yyyyMMddHHmmss.xml.
What is the right way to use application.properties for this. I guess I need to escape $ sign but escaping it like #{'$'} didn't help.
Use $simple{date:now:yyyyMMddHHmmss}, see the alternative syntax information bot at: http://camel.apache.org/simple.html
Related
I am trying to setup spring cloud config using local file system. However, I couldn't get it working.
Below is my application.properties file:
spring.application.name=spring-cloud-config-servers
server.port=8888
spring.profiles.active=native
spring.cloud.config.server.native.searchLocations=classpath:/config
Inside limits-service.properties, I have the following:
limits-service.minimum=4
limits-service.maximum=400
Once i run the server, i get the following. Please help in fixing it.
It might be a simple mistake of naming?
For example, your spring application name is "limit-service" while your property files are named "limits-service" and that might be why it is not reading them.
yes above one it is working, spring.applicatiom.name must be equals to the properties file(Lets say uppercase must follow uppercase of properties file as well )
I found a solution to do it via Java code here:
https://docs.spring.io/spring-batch/docs/4.2.x/reference/html/job.html#configuringJobRepository
But, I want to do it if possible in a simple way via configuration in yaml format in the batch configuration file.
Thank you.
As far as I know, there is currently no such property in yaml available.
There is an open feature request in Spring Boot (https://github.com/spring-projects/spring-boot/issues/28802) that may result in a property like spring.batch.jdbc.isolation-level-for-create in the future. Until then, you'll need to use Java (or XML) configuration.
I am using application.properties file for some static properties like username and password but I want to change those parameters without stopping my application I was trying this with actuators but I failed.
I would also suggest to use Spring Cloud Config.
Here is a pretty good article about how this works:
https://nirajsonawane.github.io/2019/02/22/Update-Configs-Dynamically-Using-Spring-Cloud-Bus-and-Spring-Cloud-Config/
I have a Spring Boot property source file containing a set of arbitrary properties. I would like to get all of those properties and add them to the environment.
I tried injecting the Environment into the class, and I am able to use that to get known properties. But I am not sure how to get all properties from there.'
If course I can use a traditional Properties.load() but is there a Spring way to do that?
Have you tried #PropertySource anotation?
I wouldn't recommend using PropertySource because you can't configure the precedence of the properties that you add. You may want that these properties can be overridden in some way, maybe? Or you may want that these properties take precedence over others. For this, I recommend you implement an EnvironmentPostProcessor.
There is a sample in this university session at Devoxx where we showcase how to read a file from the home directory and add it after command line properties. You could do pretty much the same thing and order them the way you want.
The sample app is available here if you want to give that a try.
If you put your properties into the "application.properties" (or any of the other places described here), the properties are automatically available in Spring's Environment.
One way to access the properties then is simply to #Autowire the Environment into the class where you want to access it.
I am reading/practicing a security management tutorial with Spring-boot. I noticed that I could customize the application by using either a file named application.properties or a file named application.ymldepending on the syntax I prefer.
Then I reached a point in the tutorial where it is asked to put this piece of information in application.yml :
security:
sessions: NEVER
Problem : this piece of configuration is obviously arborescent and fits well in application.yml but what would be the equivalent in application.properties which, AFAIK, like every .properties files is not meant to store arborescent data?
Where YAML uses new lines and indentation, a properties file uses . separators. The equivalent configuration in application.properties would be:
security.sessions=NEVER