5

I have a Spring Boot multi-module maven project. I want my library module to handle its own properties.

So, in the library module:

src/java/resources/module-name/application.properties
src/java/resources/module-name/application-dev.properties
src/java/resources/module-name/application-prod.properties

I have a @Configuration class in that module with:

@PropertySource("classpath://module-name/application-dev.properties")

Obviously, this will only load the dev properties.

2 Questions:

1) How do I factor in @Profile in here so I don't have to create multiple configuration classes, each with its own @Profile. Is there a way to combine the annotations or parameterize them with something like application-${spring.active.profile}.properties?

2) How do I achieve the same behavior vis-a-vis application.properties file as I would have out of the box if these files were in the root of the classpath and picked up automatically by Spring? In other words, I'd like to place all the common properties into application.properties file and only the profile specific ones into application-dev.properties or application-prod.properties ones.

user1902183
  • 3,203
  • 9
  • 31
  • 48
  • Possible duplicate of [Can @PropertySources be chosen by Spring profile?](https://stackoverflow.com/questions/12691812/can-propertysources-be-chosen-by-spring-profile) – jonrsharpe Dec 04 '17 at 22:17
  • Spring Boot supports this out-of-the-box why would you need additional complexity? See https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config – M. Deinum Dec 05 '17 at 07:16

0 Answers0