Announcement Announcement Module
Collapse
No announcement yet.
Autowiring remote EJB3 with @EJB annotation via JNDI Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Autowiring remote EJB3 with @EJB annotation via JNDI

    Hi,

    I want to autowire my EJB into Spring managed bean. EJBs are deployed on remote JBoss5. On Tomcat I managed to connect to JBoss, but got error:
    Code:
    org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'foo/SessionService' must be of type [foo.ejb.SessionService], but was actually of type [javax.naming.Reference]
    Can anyone tell me how to get this EJB properly? I don't want to list every EJB explicitly in applicationContext.xml because I do have annotations. Is it possible to do without listing every EJB in some xml file?

    Here is what I have now:
    Code:
    	<bean id="simpleJndiBeanFactory" class="org.springframework.jndi.support.SimpleJndiBeanFactory">
    		<property name="jndiEnvironment">
    			<props>
    				<prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
    				<prop key="java.naming.factory.url.pkgs">org.jboss.naming.client</prop>
    				<prop key="java.naming.provider.url">jnp://localhost:1099</prop>
    			</props>
    		</property>
    	</bean>
    	<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor">
    		<property name="alwaysUseJndiLookup" value="true"/>
    		<property name="jndiFactory" ref="simpleJndiBeanFactory"/>
    	</bean>
    
    	<context:component-scan base-package="foo.web" />

  • #2
    Autowiring remote EJB3 with @EJB annotation via JNDI - self reply

    Hello again,

    As I wasn't going to sit and wait for an answer i dug a little deeper myself. I found several suggestions, that such error is caused by missing JARs. After adding 13 or so JARs from jboss/client to my WAR everything works smoothly

    For those using Maven:
    Code:
    		<dependency>
    			<groupId>org.jboss.naming</groupId>
    			<artifactId>jnp-client</artifactId>
    			<version>5.0.1.GA</version>
    			<scope>compile</scope>
    		</dependency>
    		<dependency>
    			<groupId>org.jboss.client</groupId>
    			<artifactId>jboss-client</artifactId>
    			<version>5.0.1.GA</version>
    			<scope>compile</scope>
    		</dependency>
    		<dependency>
    			<groupId>org.jboss.remoting</groupId>
    			<artifactId>jboss-remoting</artifactId>
    			<version>2.5.0.SP2</version>
    			<scope>compile</scope>
    		</dependency>
    		<dependency>
    			<groupId>org.jboss.ejb3</groupId>
    			<artifactId>jboss-ejb3-proxy-client</artifactId>
    			<version>5.0.1.GA</version>
    			<scope>compile</scope>
    		</dependency>
    		<dependency>
    			<groupId>org.jboss.ejb3</groupId>
    			<artifactId>jboss-ejb3-common-client</artifactId>
    			<version>5.0.1.GA</version>
    			<scope>compile</scope>
    		</dependency>
    		<dependency>
    			<groupId>org.jboss.ejb3</groupId>
    			<artifactId>jboss-ejb3-core-client</artifactId>
    			<version>5.0.1.GA</version>
    			<scope>compile</scope>
    		</dependency>
    		<dependency>
    			<groupId>org.jboss.ejb3</groupId>
    			<artifactId>jboss-ejb3-security-client</artifactId>
    			<version>5.0.1.GA</version>
    			<scope>compile</scope>
    		</dependency>
    		<dependency>
    			<groupId>org.jboss.aop</groupId>
    			<artifactId>jboss-aop-client</artifactId>
    			<version>2.0.1.GA</version>
    			<scope>compile</scope>
    		</dependency>
    		<dependency>
    			<groupId>org.jboss.aspect</groupId>
    			<artifactId>jboss-aspect-library</artifactId>
    			<version>1.3</version>
    			<scope>compile</scope>
    		</dependency>
    		<dependency>
    			<groupId>oswego-concurrent</groupId>
    			<artifactId>concurrent</artifactId>
    			<version>1.3.4-jboss</version>
    			<scope>compile</scope>
    		</dependency>
    		<dependency>
    			<groupId>org.jboss.security</groupId>
    			<artifactId>jbosssx-client</artifactId>
    			<version>2.0.2.SP6</version>
    			<scope>compile</scope>
    		</dependency>
    		<dependency>
    			<groupId>org.jboss.security</groupId>
    			<artifactId>jboss-security-spi</artifactId>
    			<version>5.0.1.GA</version>
    			<scope>compile</scope>
    		</dependency>
    		<dependency>
    			<groupId>javax.security</groupId>
    			<artifactId>jacc</artifactId>
    			<version>1.0</version>
    			<scope>compile</scope>
    		</dependency>
    		<dependency>
    			<groupId>org.jboss</groupId>
    			<artifactId>jboss-integration</artifactId>
    			<version>5.0.1.GA</version>
    			<scope>compile</scope>
    		</dependency>

    Comment


    • #3
      Tomcat - Glassfish - Remote EJB

      Iassan,
      I know its been over a year but I'm in a similar situation. However I can't get Tomcat to see remote EJBs on Glassfish. I've setup my spring config in a similar manor as you have above, but with glassfish classes in SimpleJndiBeanFactory instead of JBoss. I have a servlet defined in my project that I want to connect to my remote ejb. I have this in my 'local' servlet:

      @EJB(mappedName="remoteEJB")
      private RemoteService remoteService;

      When I access the servlet it fails with this:
      javax.naming.NameNotFoundException: Name com.mycompany.app.ServletTest is not bound in this Context

      In your first post, you said you got Tomcat to talk to JBoss. Any change you could get some pointers on trying to get Tomcat to see Glassfish?

      Thanks!

      Comment


      • #4
        Hi sellerjd,

        I'm sorry, but I have never worked with Glassfish, so I can only guess or direct you in some general direction.

        From your exception I would try to see what is registered in your context. Maybe it's not problem with resolving EJBs from your servlet but registering EJBs.

        In my case problem was how to get to JNDI, yours is different.

        Best regards,

        Jacek Bilski

        Comment


        • #5
          hi Iassan.....
          ur post is nice & it is very useful.....

          Comment


          • #6
            iassan Its a Really Helpful Post ThaNkxx Man.. =)

            Comment

            Working...
            X