Java config equivalent of echcache.xml - ehcache

Is there a sample Java Config for a standard ehcache XML config file (ehcache.xml) . I am using Spring 3.1.

Take a look at the provided documentation, there are some good code snippets, too: http://www.ehcache.org/documentation/user-guide/configuration

Specifically: "Adding and Removing Caches Programmatically": http://www.ehcache.org/documentation/2.5/code-samples#adding-and-removing-caches-programmatically

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.

How to generate code from an openapi file?

is it possible to generate java code from the openapi definition file with quarkus?
Or should I use an external tool ?
Quarkus itself won't do that for you. You need to use another tool.
Have a look at https://github.com/OpenAPITools/openapi-generator. I don't think Quarkus can do that.
Quarkus could generate an openapi yaml file from your quarkus project, which you could again use for openapi client generation.
For that take a look here https://quarkus.io/guides/openapi-swaggerui
This project is now available: https://github.com/quarkiverse/quarkus-openapi-generator. Works as expected.

Quarkus: How to define and read properties file (or application.properties) outside application or at runtime?

In Quarkus, We have properties file inside project itself called application.properties.
Is there any Quarkus way to define external properties file in my use case like i am developing a mail sender and i want to add recipients in future.
Is it possible to give application.properties outside at local and inject it at runtime?
You can add a configuration file in your application working directory under config/application.properties : https://quarkus.io/guides/config#overriding-properties-at-runtime
There is ongoing discussion to have more runtime configuration capabilities here: https://github.com/quarkusio/quarkus/issues/1218
You can achieve this by keeping .properties (or .yaml) in Spring Cloud Config Server.
It's really easy to set it up. It's is well documented in following link (official documentation):
Quarkus - Reading properties from Spring Cloud Config Server
As loïc says, you can follow the convention and create a config/application.properties. You can also use the property quarkus.config.locations to specify additional config locations. It can be defined at runtime like below
java -Dquarkus.config.locations=app-config/config.properties -jar my-app.jar

Using dotenv files with Spring Boot

I'd like to use dotenv files to configure my Spring Boot application.
What is the best way to do this?
In Ruby or Node world, I just creating .env file and it loads all stuff from there to application environment.
I don't like to create separate profiles for my app etc. I just want to load any environment variables I specified in file into my app.
In spring boot just do that in application.yml
---
spring:
config:
import: optional:file:.env[.properties]
username: ${USERNAME}
or if you use application.properties
spring.config.import=optional:file:.env[.properties]
username=${USERNAME}
Then #value and all other stuff will work
I have built a proper integration between Spring and dotenv.
Follow this thread to understand the motivation. And then review the library:
Check out the spring-dotenv library here:
https://github.com/paulschwarz/spring-dotenv
The library includes a sample application to show you how to use it, and there you see that the integration with Spring is very natural:
https://github.com/paulschwarz/spring-dotenv/tree/master/application/src/main/resources
I stuck to two principles in designing this library:
https://12factor.net/config
Allow your code to be completely unaware of dotenv so that you continue to reference your application.yml/application.properties files using the normal Spring techniques. No funny business.
There's actually a java port of 'dotenv' tool.
https://github.com/cdimascio/dotenv-java

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.

Resources