Announcement Announcement Module
Collapse
No announcement yet.
Using Spring AOP with CGLIB and Spring Data Neo4j - problem with repositories Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using Spring AOP with CGLIB and Spring Data Neo4j - problem with repositories

    Hi guys,
    I'm writing a sample web application with two sources of data: a standard RDBMS (Postgres), integrated through MyBatis, and a Neo4j graph db.
    To support transactions (only on the RDBMS side, I don't want to mix data retrieving) I enabled AOP transaction management (with tx:advice and aop:config pointcuts) with proxy-target-class="true" (CGLIB proxy implementation), as my service layer beans are implemented without interfaces.

    One of my service bean is injected with a repository bean (@Autowired), that is enabled with the following xml configuration:
    <neo4j:repositories base-package="com.mypackage.graph.repository"/>

    The signature of the repository bean is "public interface FormRepository extends GraphRepository<Form>".

    When I enable AOP config with CGLIB proxy, i receive the following error on the service bean:
    java.lang.IllegalArgumentException: Cannot subclass final class class com.sun.proxy.$Proxy75

    In fact, the CGLIB library doesn't manage to create the proxy of the service bean because there is an autowired field implemented by an interface, isn't it?

    There is a way to make it work with CGLIB configuration?

    Thanks
    Marco

  • #2
    I slept on it... and this morning i found a workaround.

    Instead of injecting the repository bean, I injected the neo4jTemplate object:

    @Autowired private Neo4jTemplate neo4jTemplate;

    then I wrote a method to return my repository:

    private GraphRepository<Form> getFormRepository() {
    GraphRepository<Form> repo = neo4jTemplate.repositoryFor(Form.class);
    return repo;
    }

    Hope this helps someone... let me know if you know a way to make it work with the standard configuration.

    bye
    Marco

    Comment


    • #3
      AspectJ configuration

      Originally posted by musmarc View Post
      let me know if you know a way to make it work with the standard configuration
      Marco,

      I had exactly the same problem as you, but I didn't want to have to get hold of repositories using the method you mentioned. I found that I had <aop:aspectj-autoproxy proxy-target-class="true" /> in my context.xml files (in 2 places), and this was causing it to fail, because of the way interfaces are used for repositories in Spring-data-neo4j : there are no concrete 'target' classes.

      By changing this to 'false', the whole thing started working. Hope this helps you.

      Regards,
      Mick

      Comment

      Working...
      X