Skip to content
Advertisement

@PropertySource fails to autowire required class (Spring Boot 2.3.8.RELEASE)

I have the following class I plan on using to autowire an instance of a Spring class named AADAppRoleStatelessAuthenticationFilter:

JavaScript

Although the default-integration.yml file is well placed under /resources (no ‘FileNotFoundException’ is thrown), it seems like during the application start-up, Spring, for whatever reason, is not able to read it’s content (or disregards it while trying to initialize aadAppRoleStatelessAuthenticationFilter).

enter image description here

It throws errors related to missing properties, which do exist (if I move the properties as they are into the application.yml file – the autowiring completes successfully).

JavaScript

My default-integration file:

JavaScript

Advertisement

Answer

Yes I ran into exactly this issue, this is how I resolved it.

First, you need to define a YamlPropertySourceFactory class:

JavaScript

Now you can use this on the beans where you want to use a yaml file as your PropertySource. For example:

JavaScript
Advertisement