Change ValidationMessages.properties location - internationalization

Is it possible to change the name and location of the ValidationMessages.properties file? By default, it should be inside the classes directory of the war file (root of the classpath).
I am using Hibernate Validator and RestEasy as my JavaBean Validation and JAX-RS providers.

You can override the MessageInterpolator defined in the configuration and pass it a different resource bundle locator.
We have everything explained in this section of the reference documentation.

Related

is there a way to set default value of spring configuration property when some dependency/jar resp. it's classes are available in classpath?

example:
I have groupId=myGroup, artifactId=feignOkHttp dependency jar file.
In case I want to do some standard auto-configuration there, I would create auto-configuration classes and refer it in META-INF/spring.factories
However, here I need to set configuration property value usually placed in application.properties/.yml
feign.okhttp.enabled=true
the property is used in spring's or 3rd-party artifact's auto-configuration classes.
Is it somehow possible or do I need to set it in application.properties/.yml file in each project where I will include my dependency?

Conflict with config class in dependency (Spring AsyncConfig)

My team uses some starter code that's included in every internal Spring project by default. This is included as a dependency (not parent) in the pom.xml file of my project. This starter code contains a default implementation of a configuration interface which Spring does not allow duplicates of (AsyncConfigurer), but I need to create my own custom implementation. I am not sure how to resolve this. Is there a way for me to exclude this configuration class but keep the rest of the dependency? Or can I somehow keep the given config class, but modify its properties?
The specific exception I get is: java.lang.IllegalStateException: Only one AsyncConfigurer may exist
//Thank you
You can define the AsyncConfigurer on parameter excludes from #SpringBootApplication. Example:
#SpringBootApplication(exclude=AsyncConfigurer.class)
Notice that this will excludes the entire #Configuration .
Another solution is to use bean override, to define only the beans you need to replace.
Add this to your application.properties (or yaml):
spring.main.allow-bean-definition-overriding=true
And you will be able to override it.

External application.properties file overriding values in Spring Boot 2.2.1

I have seen many questions in regards to Spring Boot external configuration, in specific, externalizing a application.properties file, but didn't find a specific answer on whether property values from externalized application.properties files should be merged or the whole .properties file on the classpath should be overridden with the external one.
After recent app upgrade to Spring Boot 2.2.1-RELEASE version, there was a need to enable bean overriding with spring.main.allow-bean-definition-overriding=true property, which is set in the application.properties file on the classpath. Since we want to use an external application.properties file, I created one(same name) without the aforementioned property and loaded it with the following property in IntelliJ:
java -jar appName.jar --spring.config.location="C:\Users\User\Downloads\application.properties"
The error came up as though the external props file completely overrode the classpath file, without looking for the mentioned property in the classpath file and using the missing property from the classpath application.properties:
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'userRepository' could not be registered. A bean with that name has already been defined and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
After adding the bean overriding property to the external application.properties file, but removing it from the classpath one, error is gone.
In Spring docs, it is clearly stated that :
Spring Boot uses a very particular PropertySource order that is designed to allow sensible overriding of values. Properties are considered in the following order:
...
Application properties outside of your packaged jar (application.properties and YAML variants).
Application properties packaged inside your jar (application.properties and YAML variants).
After testing it out with IntelliJ and a packaged jar, both method exhibit the same: seems like the whole file is being overridden and values are not merged, but only loaded from the externalized properties file. My questions is, is this the expected behavior or am I missing out on something ?
EDIT: tested the behavior with jar

How can I pass certain properties to the Spring context through servlet params?

So we decided to deploy our application no more as a war on the usual tomcat, but from an embedded jetty. My app uses context:property-placeholder to resolve properties from a file. Now I'd need to pass some (or all) properties programatically before starting jetty. Is there a way that allows me to set some properties by code, before running jetty, instead of relying on the .properties file? For example as Servlet params?
You can use ServletContextPropertyPlaceholderConfigurer. This PropertyPlaceholderConfigurer extract the properties from the servlet context init params.
From Spring Javadocs:
Subclass of PropertyPlaceholderConfigurer that resolves placeholders as ServletContext init parameters (that is, web.xml context-param entries).
But this class is deprecated from Spring version 3.1.
From version 3.1 you don't need to use any special configuration because all Web Based servlet context use the class org.springframework.web.context.support.StandardServletEnvironment that resolve properties from servlet context params by default.

Annotating Groovy beans to load within Spring

Our application uses #Bean to define create beans and load them into the Spring context.
We now need to externalize these, so as to enable the application to be configured without touching the java source code.
We wish to replace the #Bean's with Groovy classes.
Is there a way to annotate a Groovy bean so that it will be picked up by Spring?
Note that we cannot simply reference each Groovy bean in the Spring XML, as we need to add and modify beans without touching the Spring code.
Thanks very much.
Use Spring config inheritance.
Move all shared code in a common "base" project that each individual / specific project depends on. Use Maven for this.
Create a common / base Spring config and put that into the "base" project. This config doesn't contain a definition for ProcessDefinition
In the specific project, create one bean which inherits from ProcessDefinition. Create a Spring config which imports the base config and define the single specific bean in it.

Resources