@SpyBean does not work when used to spy on a Spring Data Repository

See original GitHub issue

Version: Spring Boot 1.4.1 Subject: @SpyBean on Data Jpa Repository bean isn’t working Exception thrown:

UnsatisfiedDependencyException: Error creating bean with name 'cityService' defined in file [...\target\classes\com\example\CityService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cityRepository': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Object of class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean] must be an instance of interface com.example.CityRepository

Demonstration project: https://github.com/igormukhin/spring-boot-issue-6871 USE BRANCH: spybean-on-jparepository

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:52
  • Comments:64 (17 by maintainers)

github_iconTop GitHub Comments

21reactions
igormukhincommented, Oct 11, 2016

@philwebb I stunble upon it as I worked on an integration test where I wanted to check if a specific save operation is called at the end. But still I needed that all other (find… methods) to work as usual.

As a workaround I’m checking if the saved entry is in the database.

11reactions
hashpyritcommented, Dec 19, 2016

At the end of the day, it’s not too often people have to use spies but there are cases when it’s the option that gets the job done.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mockito cannot create Spy of @Autowired Spring-Data ...
This worked very well with the Service layer but I have problems with the Repository layer. My setup is as follows: Mockito -...
Read more >
Using Spring Boot @SpyBean - Shekhar Gulati
We made MongoTemplate a spy by annotating it with @SpyBean annotation. This does not override the Spring application context with a mock bean....
Read more >
Spring Boot - Testing With @SpyBean - LogicBig
Similar to @MockBean, Spring Boot provides @SpyBean annotation to apply Mockito spies to a Spring ApplicationContext.
Read more >
@SpyBean Example in Spring Test - ConcretePage.com
The @SpyBean is a Spring Boot test annotation that is used to add ... When we mock an object of a class, we...
Read more >
46. Testing - Spring
A Spring Boot application is a Spring ApplicationContext , so nothing very ... If you are using @SpyBean to spy on a bean...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found