Skip to content

Clarify contradictory advice on the use of @PropertySource #18900

@wilkinsona

Description

@wilkinsona

The docs currently say:

A nice way to augment and modify this ordering is to add @PropertySource annotations to your application sources. Classes passed to the SpringApplication static convenience methods and those added using setSources() are inspected to see if they have @PropertySources. If they do, those properties are added to the Environment early enough to be used in all phases of the ApplicationContext lifecycle.

And:

While using @PropertySource on your @SpringBootApplication may seem to be a convenient and easy way to load a custom resource in the Environment, we do not recommend it, because Spring Boot prepares the Environment before the ApplicationContext is refreshed. Any key defined with @PropertySource is loaded too late to have any effect on auto-configuration.

The former is recommending what the latter says is not recommended.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions