4 Replies Latest reply on May 18, 2012 7:19 PM by paul_

    @Resource Annotation fails to inject custom Connectionfactory

    paul_

      Hi,

       

      i'm trying to get JBoss 7 (7.1.1) hooked up with the Neo4J Database. There is already a working connector for that (http://alexsmirnov.wordpress.com/2011/05/18/neo4j-java-ee-connector/)

       

      Deployment and startup of my application are no problem.The connectionfactory gets bound to its jndi name at startup:

      [org.jboss.as.deployment.connector] (MSC service thread 1-9) JBAS010406: Registered connection factory java:/eis/Neo4j

      [org.jboss.as.deployment.connector] (MSC service thread 1-9) JBAS010401: Bound JCA ConnectionFactory [java:/eis/Neo4j]

       

      But the trouble starts when I want to use the database / the connectionfactory. I inject the connectionfactory with the @Resource Annotation like this:

      (NEO4J_NAME = "java:/eis/Neo4j")

       


      @Resource(lookup=NEO4J_NAME)

      private Neo4JConnectionFactory connectionFactory;

       

      As soon as I call any method on the connectionFactory (connectionFactory.getConnection() for example) JBoss starts beating me up:

       

      ...

       

      Caused by: java.lang.IllegalArgumentException: Can not set com.netoprise.neo4j.connection.Neo4JConnectionFactory field test.Neo4jClient.connectionFactory to com.netoprise.neo4j.connection.Neo4JConnectionFactoryImpl

       

      (Neo4JConnectionFactory obviously is the interface and *Impl is the corresponding implementing class for that interface..)

       

       

      I already tried different paramters for the @Resource annotation (mappedBy, name), even tried a jndi lookup by hand (which gives me a classcastexception)

       

      Maybe I'm missing something obvious but I've been pulling my hair out over this one..

      Any hints would be greatly appreciated.

       

      Greetings from Germany

       

      p.salg

      ____

      Edit:

       

      I attached the snippet from the standalone.xml config file which I'm using, maybe this will help a little more.

        • 1. Re: @Resource Annotation fails to inject custom Connectionfactory
          sfcoy

          This looks like a classloading problem.

           

          Does your application contain a JAR with the Neo4JConnectionFactory class file in it?

           

          If so, try removing it from the runtime deployment.

          1 of 1 people found this helpful
          • 2. Re: @Resource Annotation fails to inject custom Connectionfactory
            paul_

            Well yes, my EAR contains "neo4j-connector-api-0.3-SNAPSHOT.jar" which has Neo4jConnection.class and Neo4jConnectionFactory.class in it.

             

            What exactly do you mean by "remove it from the runtime deployment"? I think I would need the jar in the ear so I can use the ConnectionFactory ?

             

            Packaging in my project is as follows:

             

            EAR

                 - lib

                      - neo4j-connector-api-0.3-SNAPSHOT.jar

            WAR

                 - src

                      - Neo4jClient (Which has the @Resource Annotation in it)

                      - TestBean (Stateless Bean to get called from View (Richfaces 4) )

                 - WebContent

                      - index.xhtml

                      - WEB-INF

                           - beans.xml

                           - faces-config.xml

                           - web.xml

                           - lib

                                - Richfaces 4 libs & dependencies

             

            A little confused =D

             

            Greetings from Germany,

            ps

            • 3. Re: @Resource Annotation fails to inject custom Connectionfactory
              paul_

              Okay, I finally got it working.

               

              My current solution is this:

               

              - I removed the WAR from my EAR File,

              - As Stephen suggested, I removed the neo4j-connector-api-0.3-SNAPSHOT.jar from the build path of the project

              - Instead I put the neo4j-connector-api-0.3-SNAPSHOT.jar in jdk/jre/lib/endorsed directory which is used to build the project and run the server with

              - deployed neo4j-connector.rar in {server-home}/standalone/deployments

              - added jboss-deployment-structure.xml file in {war}/webcontent/web-inf    (as seen in http://groups.google.com/group/xadisk/browse_thread/thread/47b7324ece6b884a?pli=1)

              - configured the server to use the connector (see <subsystem xmlns="urn:jboss:domain:resource-adapters:1.0">)

              - then injected the connectionfactory in my class with @Resource annotation   (as seen in http://alexsmirnov.wordpress.com/2011/05/18/neo4j-java-ee-connector/)

               

              I will provide a full tutorial as well as soon as I've written it.

               

              Thanks for the help =)

               

              Greetings from Germany

              ps

              • 4. Re: @Resource Annotation fails to inject custom Connectionfactory
                paul_

                I have completed the tutorial now, it can be found here:

                http://sblog.de.nu/wp/?p=6

                 

                (Though I still didn't get it working with an EAR.. will look into that again)

                 

                Greetings from Germany

                ps