-
Notifications
You must be signed in to change notification settings - Fork 41.4k
Closed
Labels
type: regressionA regression from a previous releaseA regression from a previous release
Milestone
Description
Issue
Starting from Spring-Boot 3.2.x the @SpyBean is not able to initialize MongoRepository bean of the generic type.
Please check the example project: https://github.com/pavlo-reshetniak/spybean-issue-example
How to reproduce
- Make sure the spring-boot-starter-parent has version 3.2.x (e.g. 3.2.4) in the parent POM file
- Run unit test: com.example.service.ExampleServiceTest#shouldExtractDataFromMongo
Result
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.example.repository.ExampleRepository]: Specified class is an interface
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:77)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1311)
... 39 more
Possible workaround
- Downgrading the spring-boot-starter-parent to version 3.1.10 will fix the issue
- Removing the generic type under the @SpyBean initialization will fix the issue:
From this:
@SpyBean
private ExampleRepository<ExampleData> exampleRepository;
to this:
@SpyBean
private ExampleRepository exampleRepository;
Metadata
Metadata
Assignees
Labels
type: regressionA regression from a previous releaseA regression from a previous release