Beto Neto
Beto Neto

Reputation: 4102

@PropertySource and Application context name

I have an @Configuration class. This class, has a @PropertySource.

I want to have one different property to each application.

Example:

@Configuration
@PropertySource("file:${my.properties-file}")
public class Config {
}

I want to configure each property to each application via it context name.

My application server directory structure:

webapps/
     my-app-a.war
     my-app-b.war

Both (my-app-a.war and my-app-b.war) are the same web application, the difference is that they are deployed twices in different contexts.

For that reason, I need to configure this 2 properties:

my.properties.my-app-a=/source/properties/a.properties
my.properties.my-app-b=/source/properties/b.properties

How can I create a custom property source resolver to inject/consider the application context name to load the properties file?

Upvotes: 2

Views: 528

Answers (2)

Beto Neto
Beto Neto

Reputation: 4102

I solved setting a context configuration per-application.

Apache Tomcat 8 Configuration Reference - Defining a context

Upvotes: 1

user4768018
user4768018

Reputation: 131

Did you try using spring profiles? Or with maven you can put your properties in the pom, and based on the profile to build your war they will be inserted in the properties file

Upvotes: 0

Related Questions