1

I'm building a framework which can be used with/without Spring. So, I can't use the @PropertySource annotation.

How can I know exactly the application.properties path considering all possible variation. eg the user have changed the default path using --spring.config.location

Is there any Spring runtime variable which I can get this path?

2
  • Use environment variables instead of properties to set your configuration values. Commented Jun 26, 2018 at 17:42
  • You could also provide a own spring-boot-starter for your framework which then provides the configuration via spring-configuration-properties and also wraps your framework perfectly for usage in a springboot app Commented Jun 26, 2018 at 18:10

1 Answer 1

1

just inject the Environment

@Autowired
private Environment environment;

it cointans a propertySourceList, which contains all property sources :)

maybe this is also interesting for you:

Sign up to request clarification or add additional context in comments.

2 Comments

oh, damn, you mean no spring at all? :D
If I understand my spring, the @Autowired will fail with no spring environment, and then you can grab params from the system properties. I would wrap the class's property util and put the Environment var inside it, then optionally get other params when it's null.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.