Using Spring Boot 3.1.5 version @MockBean annotation works charming, however after trying Spring Boot 3.2.0-SNAPSHOT - without any code change, looks like it stopped working as it not mocking @Autowired objects anymore.

It looks like it affects FeignClients classes (annotated by @FeignClient).

Is this a known issue?

Let me know if you have any question.

Comment From: philwebb

We're not aware of any issues and I don't believe we've changed any of the code in that area for a while. If you can provide a sample project that works with Spring Boot 3.1 but fails with Spring Boot 3.2 we can investigate further.

Comment From: trcoelho

Hi @philwebb , thanks for your quick reply. Please find attached a compressed folder which has two projects inside:

  • mockbean-31 which has 3.1.5 Spring Boot dependencies
  • mockbean-32 which has 3.2.0-SNAPSHOT Spring Boot dependencies

Either has same code base without any differences.

To run, just go through folder and run:

mvn test

Let me know if you have any question.

mockbeans.zip

Comment From: wilkinsona

Thanks for the sample. The change in behavior is due to https://github.com/spring-cloud/spring-cloud-openfeign/commit/2a5e815b6b003aef863cef6af136c801ca4222d8. The removal of the attribute means that Spring Boot's @MockBean support can no longer identify the type that will be produced by the FeignClientFactoryBean. Rather than removing the attribute, I think its type should have been changed from a String to a Class.

Please open a Spring Cloud OpenFeign issue so that they can investigate.

Comment From: wilkinsona

You can work around the problem by specifying the name of the bean that you want the mock to replace:

@MockBean(name = "com.mockbean.client.CallableClient")

Comment From: trcoelho

Thank you everyone! Have opened an issue on Spring Cloud board regarding this matter.