Hi. I'm updating my project from Spring Boot 2.6.4 to 3.0.2. I've firstly updated the project to version 2.7.8 and everything worked fine, but jumping from 2.7.8 to 3.0.2 broke the integration tests. In particular, it looks like that the application.yaml file I've under src/test/resources doesn't get loaded at all and, as such, the application context can't be instantiated.

Am I missing something to migrate in order to make @SpringBootTest load such a file as before?

Comment From: wilkinsona

As far as I can recall, this hasn't changed in 3.0.x. An application.yaml file in src/test/resources ends up on the classpath and is loaded from there. Perhaps there's a classpath ordering problem which means that another application.yaml file from a different location is appearing earlier in the classpath.

If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

Comment From: cdprete

Hi @wilkinsona. It has been difficult to reproduce it in a demo project since the cause was unknown, but now I can at least say it happens when the @ConfigurationProperties class has some (sort of?) parameters in its constructor. A demo is attached: demo.zip

In my real project I need to get some beans in the props, so that I can calculate some fallbacks in a @PostConstruct if some props are missing.

Comment From: wilkinsona

Thanks for the sample. The problem's unrelated to application.yaml and the test classpath.

The behavior that you're seeing is due to MyConfigProperties having a single non-default constructor. This results in Boot's configuration properties support using that constructor for binding. As described in the documentation, if you don't want that constructor to be used for property binding, it should be annotated with @Autowired. This will result in any MyBean beans being injected into the constructor and property binding being performed using JavaBean getters and setters.

Comment From: cdprete

Thanks for the sample. The problem's unrelated to application.yaml and the test classpath.

The behavior that you're seeing is due to MyConfigProperties having a single non-default constructor. This results in Boot's configuration properties support using that constructor for binding. As described in the documentation, if you don't want that constructor to be used for property binding, it should be annotated with @Autowired. This will result in any MyBean beans being injected into the constructor and property binding being performed using JavaBean getters and setters.

Hello. I see. On the other end, this was not the case in the previous version, though. I'll give it a try and close the ticket if it works as expected.

Comment From: wilkinsona

this was not the case in the previous version, though.

Correct. This change in 3.0 is described in the release notes.