Skip to content

Bean Overrides like @MockitoBean and @TestBean should not be allowed on static fields #33922

Closed
@sbrannen

Description

@sbrannen

It's currently possible to declare a bean override field as static.

For example, the following currently works in a test class.

@MockitoBean
static ExampleService service;

However, support for static fields was unintentional and does not align with @Autowired semantics where the annotated field cannot be static.

In light of that, we should reject static bean override fields.

Metadata

Metadata

Assignees

Labels

in: testIssues in the test moduletype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions