Announcement Announcement Module
Collapse
No announcement yet.
Why jpa:repositories picks up all @Repository classes? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:
    Code:
     <jpa:repositories base-package="com.company.dao.jpa" />
    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. com.company.dao.jpa). 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.
    Code:
    nested exception is java.lang.IllegalArgumentException: Can not set com.company.dao.SomeDaoUsingJdbcDirectly field com.company.dao.SomeOtherDaoUsingJdbcDirectly.someDaoUsingJdbcDirectly 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 interface.so 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.

    Comment

    Working...
    X