Writing file properties with spring boot - spring

I've used the #PropertySource and #Value annotations for reading external file properties and it works great. But if I want to write the same #Value annotated properties out to an external file, can that be done? I've done some searching but can't seem to find a way of doing it. Is there native support for this?

You should have a look at the DefaultPropertiesPersister. An example is provided here.

Related

How can I set isolation-level-for-create via yaml configuration file for spring batch

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.

Spring boot 2.4 Reverse document order

In spring boot 2.4, later loaded properties override earlier properties.
But, for my need, I am importing document inside document using spring.config.import. Say, import abc.properties from application.properties.
But, I need to override, later loaded properties with earlier loaded ones.
Say, application.properties should override abc.properties. not the other way arpund.
Please help me on how to do this.
Thanks in advance.
I resolved the issue with EnvironmentPostProcessor, as it seems to be not doable simply with spring.config.import.
As, both yaml (and in terns json) and properties, property source parser is readily available in spring boot, this required very little coding.

How can I directly add properties from a Spring Boot property source to the environment

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.

katharsis configured with spring xml

It looks, from the source code, that Katharsis-spring module will only work with spring boot.
My question then, is it possible to configure a spring project in xml and load Katharsis without spring boot?
If so, how would you need to configure katharsis in spring xml?
Has anyone done this before and willing to share an example?
Thanks.
Only work with Spring boot? That doesn't seem possible. Just #Import(KatharsisConfigV2.class) on any configuration in your code and it should work.
As for xml config: By design, if it can be done in code it can be done in config.
Try that and let me know how you make out
With version 2.8.1 of katharsis, it is quite a challege to get this configured just in xml. So I looked at the master branch of the project and found that there are going to be some new features which will make it easier to configure with spring xml. I have created a sample project here you can use as reference for configuration:
Sample Spring/Katharsis Project with XML configuration
In the sample project I added the SpringServiceDiscovery class, and modified the KatharsisBoot class to make the configuration easier. With the next release of this project, I should be able to remove these 2 classes completely, and use the classes that come with katharsis.
The beans I needed to add to my root-context.xml file were the following:
io.katharsis.spring.KatharsisFilterV2
io.katharsis.spring.ErrorHandlerFilter
com.springkatharsisxml.katharsis.boot.KatharsisBoot
io.katharsis.queryParams.QueryParamsBuilder
io.katharsis.resource.registry.ConstantServiceUrlProvider
io.katharsis.queryParams.DefaultQueryParamsParser
io.katharsis.module.CoreModule
io.katharsis.resource.field.ResourceFieldNameTransformer
io.katharsis.spring.boot.KatharsisSpringBootProperties
I also needed to expose the jackson objectMapper bean, as it's not done so by default in xml.
I also used the org.springframework.web.filter.DelegatingFilterProxy for the katharsisFilter and errorHandlerFilter.

Want to use #Value (reading the properties from property file) in UIMA framework

I have a property file like myProperties.properties. I want to read one property like MAX_YEARS using spring annotation #value as like below in UIMA JCasAnnotator_ImplBase extending class.
private #Value("${REQUIRED_COLUMNS}") String requiredColumns;
Or any alternatives for reading properties from property file in UIMA framework.
Thanks in advance.
Narasimha.
UIMA does not support value injection via Java annotations (from Spring or any other DI frameworks) at this time. It does support External Configuration Parameter Overrides, though.
uimaFIT offers annotations like #ConfigurationParameter to inject UIMA parameters into fields. These parameter values can come from descriptors automatically generated by uimaFIT using reflection, or they can come from pre-built XML descriptors.
When using pre-built XML descriptors, it should be possible to employ the External Configuration Parameter Overrides mechanism in conjunction with uimaFIT - but I am not sure if this has already been tried by anybody.
It may even be possible to employ the External Configuration Parameter Overrides mechanism with the descriptors internally generated by uimaFIT.
Disclosure: I am a developer on the UIMA project, focussing on uimaFIT.

Resources