Announcement Announcement Module
No announcement yet.
Why jpa:repositories picks up all @Repository classes? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why jpa:repositories picks up all @Repository classes?

    I want to use Spring Data to simplify the creation of my DAOs. To this end, I've created the required interfaces extending JpaRepository and updated my xml config to force the automatic creation of the implementation using jpa:repositories element. Here is the relevant line in my config:
     <jpa:repositories base-package="" />
    The issue I am facing is that Spring seems to pick-up every class annotated with @Repository and not just the one under the base package (i.e. This leads to all sort of errors when trying to autowired repositories that were not meant to use Spring Data. I've tried exclude-filter and include-filter with the same result.

    The error looks like this which seems to point to Spring trying to proxy a legacy repository that was never meant to be used with Spring Data.
    nested exception is java.lang.IllegalArgumentException: Can not set field to $Proxy69
    Any ideas or suggestions would be greatly appreciated.

  • #2
    IMOHO,JpaRepositoryConfigDefinitionParser added the PersistenceExceptionTranslationPostProcessor,and this processor will use JdkDynamicAopProxy to proxy your class which has any you see $Proxy69.
    I can't find somewhere to set the "proxyTargetClass" property of PersistenceExceptionTranslationPostProcessor to true,if set this to true,it will create proxy with cglib,then everything is ok.