With https://github.com/spring-projects/spring-framework/issues/29917 fixed we should consider deprecating our versions.

Comment From: wanger26

@philwebb do we want to target release 2.3.0 with this change? Also are we thinking of marking those for removal at this time?

Comment From: philwebb

We'll probably look at this in Spring Boot 3.4.0 which will be the first release to build on Spring Framework 6.2. I'm not sure yet about when well mark the existing annotations for removal.

Comment From: wanger26

Okay sounds good. I can take this one on. Do we want to take this opportunity to migrate our own usages of those two annotations over to the new spring framework ones?

Comment From: philwebb

Closing in favor of PR #39864 which we'll merge sometime after we create the 3.3.x branch. Thanks @wanger26!

Comment From: OrangeDog

What is the replacement for @MockBean on a type? For example, this was very useful:

@TestConfiguration
@Import({ /* some config shared by tests */ })
@MockBean({ /* some beans that need to be mocked in shared tests */ })
public class SharedWebTestConfig {
    // ...
}

@WebMvcTest(SomeController.class)
@Import(SharedWebTestConfig.class)
public class SomeTetsts {
    // ...
}

Now the only solution is to make the mock beans manually?

@TestConfiguration
@Import({ /* some config shared by tests */ })
public class SharedWebTestConfig {
    @Bean
    public BeanClass myBean() {
        return Mockito.mock(BeanClass.class);
    }
    // ...
}

Comment From: wilkinsona

I don't believe Framework has a direct equivalent although you don't have to resort to declaring the mock beans manually. You can use @MockitoBean on fields in a test class, its type hierarchy and, if it's a nested test class, its enclosing class hierarchy so you could move your mocks into a class that SomeTests extends. If you'd like to see @MockitoBean support something beyond this, please open a Framework issue.

Comment From: sbrannen

What Andy said is correct: Spring Framework does not support @MockitoBean at the type-level.

See also https://github.com/spring-projects/spring-framework/issues/29917#issuecomment-2428703548.

Comment From: OrangeDog

Thanks for the confirmation. The trouble with using inheritance is that you can only do it once, while all the annotation-driven config is composable.

The @Bean public Foo foo() { return mock(Foo.class); } also doesn't actually work in some cases, as the added bean proxies prevent any mock invocations.

Comment From: nmck257

fyi @OrangeDog, other readers -- I've opened a standalone issue in Spring Framework for this topic: https://github.com/spring-projects/spring-framework/issues/33925 if you've got other distinct usage patterns, feel free to add that context to the issue.