2

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?

Beto Neto
  • 3,962
  • 7
  • 47
  • 81
  • 1
    It is a bit unclear to me, did you try this and didn't it work? Or did it work but it is too much work? Also there are better ways to have multiple contexts for a single war then renaming and deploying it multiple times. Also this has nothing to do with SpEL as there are only property placeholders at play here, not SpEL. – M. Deinum Jul 13 '15 at 14:12
  • Yes @M.Deinum, I changed the question. I was wrong, I thought that the SpEL was used to resolve the property source location. – Beto Neto Jul 13 '15 at 14:17
  • 1
    Don't use `@PropertySource` but use an `ApplicationContextInitializer` instead and register the `PropertySource` manually. – M. Deinum Jul 13 '15 at 18:31

2 Answers2

1

I solved setting a context configuration per-application.

Apache Tomcat 8 Configuration Reference - Defining a context

Beto Neto
  • 3,962
  • 7
  • 47
  • 81
0

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

user4768018
  • 131
  • 1
  • 3