spring-projects / spring-data-jpa

Simplifies the development of creating a JPA-based data access layer.
https://spring.io/projects/spring-data-jpa/
Apache License 2.0
2.98k stars 1.41k forks source link

JpaRepositroy unable to be proxied #3211

Closed lixx174 closed 11 months ago

lixx174 commented 11 months ago

When I defined an inner interface and extends JpaRepositroy ,there is no proxy object in spring.

So I got an error that: Parameter 0 of constructor in com.security.infra.repository.DefaultOauth2ClientRepository required a bean of type 'com.security.infra.repository.DefaultOauth2ClientRepository$Oauth2ClientJpaRepository' that could not be found.

here is the source code: image

mp911de commented 11 months ago

If you would like us to spend some time helping you to diagnose the problem, please spend some time describing it and, ideally, providing a minimal yet complete sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

lixx174 commented 11 months ago

@mp911de I'm sorry that didn't describe it clearly.

this is the step to reproduce at spring boot 3.1.5:

  1. gradle depency : implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
  2. the core code :

    @Component
    @RequiredArgsConstructor
    public class OuterRepository {
    
    // Autowired by constructor with lombok
    private final InnerJpaRepository repo;
    
    @Repository
    public interface InnerJpaRepository extends JpaRepository<Object, Integer> {
    
    }
    }

In this case, when I start the application, the InnerJpaRepository can't be Autowired and will get an error. I konw that if I don't define InnerJpaRepository as an inner class, it's all ok.

mp911de commented 11 months ago

Thanks for the detail. By default, nested repository definitions are ignored. Please add @EnableJpaRepositories(considerNestedRepositories = true) to your configuration to enable scanning for nested repository interfaces.

lixx174 commented 11 months ago

Thanks a lot