Back Forum Reply New

Remote Session Bean Access

How to I remotely access a Session Bean using Spring?  
I've seen this question asked many times and have read all of the posts.  It is still not working for me.

Any help resolving this will be greatly appreciated!!!!

I am trying to access a session bean from JUnit.

Environment:
JBoss 5.0.0 GA
Spring 2.5.6

Here is what I have tried and the console log.

ApplicationContext:

lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;
lt;beans xmlns=quot;schema/beansquot;
xmlns:xsi=quot;2001/XMLSchema-instancequot;
xmlns:jee=quot;schema/jeequot;
xmlns:tx=quot;schema/txquot;
xsi:schemaLocation=quot;schema/beans schem...-beans-2.5.xsd    schema/jee schem...ng-jee-2.5.xsd    schema/tx schema/tx/spring-tx-2.5.xsdquot;gt;lt;jee:remote-slsb id=quot;TestEjbBeanquot; jndi-name=quot;TestEjbBean/remotequot;
business-interface=quot;com.test.ejb.TestEjbBeanRemotequot;gt;   lt;jee:environmentgt;java.naming.factory.initial = org.jnp.interfaces.NamingContextFactoryjava.naming.factory.ucl.pkgs = org.jboss.namingrg.jnp.interfaces java.naming.provider.ucl = jnp--localhost:1099       lt;/jee:environmentgt;
lt;/jee:remote-slsbgt;

lt;/beansgt;SessionBean:

package com.test.ejb;

import javax.ejb.Stateless;
import javax.interceptor.Interceptors;

import org..beans.factory.annotation.Autow  ired;
import org..ejb.interceptor.SpringBeanAuto  wiringInterceptor;

import com.test.entity.Widget;
import com.test.service.WidgetService;
import com.test.utils.SpringUtils;

@Stateless
@Interceptors(SpringBeanAutowiringInterceptor.clas  s)
public class TestEjbBean implements TestEjbBeanRemote {

@Autowired
WidgetService widgetService;

public Widget findWigetById(int pId) {
Widget widget = null;
try {
widget = (Widget) widgetService.findWidgetById(pId);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return widget;
}Remote Session Interface:

package com.test.ejb;

import javax.ejb.Remote;

import com.test.entity.Widget;

@Remote
public interface TestEjbBeanRemote {
public Widget findWigetById(int pId);
public void   createWidget(Widget pWidget);

}Code to access:

/*** TestEjbBean EJB.* lt;pgt;* Uses lazy initialization.* * @return* @throws NamingException* @throws Exception*/
public TestEjbBeanRemote getSubscriberEjbRemoteStub()
throws NamingException {
try {
return (TestEjbBeanRemote) SpringUtils.getInstance().getContext().getBean(quot;Te  stEjbBeanquot;);Accessing from JUnit Trace:

javax.ejb.EJBException: java.lang.RuntimeException: org..beans.factory.access.Bootstrap  Exception: Unable to return specified BeanFactory instance: factory key [null], from group with resource name [classpath*:beanRefContext.xml]; nested exception is org..beans.factory.NoSuchBeanDefini  tionException: No unique bean of type [org..beans.factory.BeanFactory] is defined: expected single bean but found 0
at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOu  rTx(Ejb3TxPolicy.java:77)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPoli  cy.java:83)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke  (TxInterceptor.java:190)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex  t(MethodInvocation.java:102)
at org.jboss.aspects.tx.TxPropagationInterceptor.invo  ke(TxPropagationInterceptor.java:76)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex  t(MethodInvocation.java:102)
at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInter  ceptor.java:42)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex  t(MethodInvocation.java:102)
at org.jboss.ejb3.security.Ejb3AuthenticationIntercep  torv2.invoke(Ejb3AuthenticationInterceptorv2.java:  159)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex  t(MethodInvocation.java:102)
at org.jboss.ejb3.ENCPropagationInterceptor.invoke(EN  CPropagationInterceptor.java:41)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex  t(MethodInvocation.java:102)
at org.jboss.ejb3.asynchronous.AsynchronousIntercepto  r.invoke(AsynchronousInterceptor.java:106)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex  t(MethodInvocation.java:102)
at org.jboss.ejb3.BlockContainerShutdownInterceptor.i  nvoke(BlockContainerShutdownInterceptor.java:65)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex  t(MethodInvocation.java:102)
at org.jboss.aspects.currentinvocation.CurrentInvocat  ionInterceptor.invoke(CurrentInvocationInterceptor  .java:67)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex  t(MethodInvocation.java:102)
at org.jboss.ejb3.stateless.StatelessContainer.dynami  cInvoke(StatelessContainer.java:486)
at org.jboss.ejb3.session.InvokableContextClassProxyH  ack._dynamicInvoke(InvokableContextClassProxyHack.  java:56)
at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:91  )
at org.jboss.aspects.remoting.AOPRemotingInvocationHa  ndler.invoke(AOPRemotingInvocationHandler.java:82)
at org.jboss.remoting.ServerInvoker.invoke(ServerInvo  ker.java:908)
at org.jboss.remoting.transport.socket.ServerThread.c  ompleteInvocation(ServerThread.java:742)
at org.jboss.remoting.transport.socket.ServerThread.p  rocessInvocation(ServerThread.java:695)
at org.jboss.remoting.transport.socket.ServerThread.d  orun(ServerThread.java:522)
at org.jboss.remoting.transport.socket.ServerThread.r  un(ServerThread.java:230)
Caused by: java.lang.RuntimeException: org..beans.factory.access.Bootstrap  Exception: Unable to return specified BeanFactory instance: factory key [null], from group with resource name [classpath*:beanRefContext.xml]; nested exception is org..beans.factory.NoSuchBeanDefini  tionException: No unique bean of type [org..beans.factory.BeanFactory] is defined: expected single bean but found 0
at org.jboss.ejb3.EJBContainer.invokeCallback(EJBCont  ainer.java:1113)
at org.jboss.ejb3.EJBContainer.invokePostConstruct(EJ  BContainer.java:1123)
at org.jboss.ejb3.EJBContainer.invokePostConstruct(EJ  BContainer.java:1134)
at org.jboss.ejb3.pool.AbstractPool.create(AbstractPo  ol.java:93)
at org.jboss.ejb3.InfinitePool.get(InfinitePool.java:  56)
at org.jboss.ejb3.InfinitePool.get(InfinitePool.java:  51)
at org.jboss.ejb3.pool.ThreadlocalPool.create(Threadl  ocalPool.java:53)
at org.jboss.ejb3.pool.ThreadlocalPool.get(Threadloca  lPool.java:93)
at org.jboss.ejb3.stateless.StatelessInstanceIntercep  tor.invoke(StatelessInstanceInterceptor.java:58)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex  t(MethodInvocation.java:102)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPoli  cy.java:79)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke  (TxInterceptor.java:190)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex  t(MethodInvocation.java:102)
at org.jboss.aspects.tx.TxPropagationInterceptor.invo  ke(TxPropagationInterceptor.java:76)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex  t(MethodInvocation.java:102)
at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInter  ceptor.java:42)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex  t

Follow-up - The above configuration works when I remove:
@Interceptors(SpringBeanAutowiringInterceptor.clas  s)
and
@Autowired

from the Session Bean.

So the question is:  How do I reference a session bean that contains @Interceptors annotation?

@Stateless
// @Interceptors(SpringBeanAutowiringInterceptor.clas  s)
public class TestEjbBean implements TestEjbBeanRemote {

// @Autowired
WidgetService widgetService;

@PostConstruct
public void initWidgetService() {
this.widgetService = (WidgetService) SpringUtils.getInstance().getContext().getBean(quot;wi  dgetServicequot;);
}

Ok - It helps to read the documentation...

Problem solved...

I have added the beanRefContext.xml to the classpath and that solved the issue.beanRefContext.xml:

lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;
lt;beans xmlns=quot;schema/beansquot;      xmlns:xsi=quot;2001/XMLSchema-instancequot;      xmlns:context=quot;schema/contextquot;      xsi:schemaLocation=quot;schema/beans           schem...-beans-2.5.xsd          schema/context          schema/context/spring-context-2.5.xsdquot;gt;            lt;!-- This will automatically declare several post-processors         including the AutowiredAnnotationBeanPostProcessor --gt;          lt;context:annotation-config/gt;        lt;bean id=quot;ejb-businesslayer.application.contextquot;        class=quot;org..context.support.ClassPa  thXmlApplicationContextquot;gt;       lt;constructor-arggt;lt;listgt;    lt;valuegt;applicationContext.xmllt;/valuegt;lt;/listgt;       lt;/constructor-arggt;   lt;/beangt;      
lt;/beansgt;
¥
Back Forum Reply New