<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
Dependecy Injection through Spring in EJB 3.0
</h3>
<span style="margin-bottom: 10px;">
created by <a href="http://community.jboss.org/people/amitajmani1">Amit Ajmani</a> in <i>Beginner's Corner</i> - <a href="http://community.jboss.org/message/631426#631426">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>i am trying to use SpringBeanAutowiringInterceptor.class for DI in my Stateless EJB3 </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>@Stateless</p><p>@TransactionManagement(TransactionManagementType.CONTAINER)</p><p>@Interceptors({ExceptionHandler.clss, SpringBeanAutowiringInterceptor.class})</p><p>public class InstrumentServiceEJB implements instrumentServiceRemote{</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>@Autowired</p><p>private InstrumentService instrService;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>......</p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>here is my beanRefContext.xml:</p><p><span style="color: #008080; font-size: 10pt;"><? <span style="color: #3f7f7f; font-size: 10pt;">xml</span><span style="font-size: 10pt;"> </span><span style="color: #7f007f; font-size: 10pt;">version</span><span style="font-size: 10pt;">=</span><em style="color: #2a00ff; font-size: 10pt;"><em style="color: #2a00ff; font-size: 10pt;">"1.0" encoding="UTF-8"?></em></em></span></p><p><span style="color: #008080; font-size: 10pt;"><em style="color: #2a00ff; font-size: 10pt;"><em style="color: #2a00ff; font-size: 10pt;"><beans xmlns="...."></em></em></span></p><p><span style="color: #008080; font-size: 10pt;"><em style="color: #2a00ff; font-size: 10pt;"><em style="color: #2a00ff; font-size: 10pt;"><bean class="org.springframework.context.support.ClassPathXmlApplicationContext"></em></em></span></p><p><span style="color: #008080; font-size: 10pt;"><em style="color: #2a00ff; font-size: 10pt;"><em style="color: #2a00ff; font-size: 10pt;"><constructor-arg></em></em></span></p><p><span style="color: #008080; font-size: 10pt;"><em style="color: #2a00ff; font-size: 10pt;"><em style="color: #2a00ff; font-size: 10pt;"><list></em></em></span></p><p><span style="color: #008080; font-size: 10pt;"><em style="color: #2a00ff; font-size: 10pt;"><em style="color: #2a00ff; font-size: 10pt;"><value>/META-INF/applicationContext.xml</value></em></em></span></p><p><span style="color: #008080; font-size: 10pt;"><em style="color: #2a00ff; font-size: 10pt;"><em style="color: #2a00ff; font-size: 10pt;"></list></em></em></span></p><p><span style="color: #008080; font-size: 10pt;"><em style="color: #2a00ff; font-size: 10pt;"><em style="color: #2a00ff; font-size: 10pt;"></constructor-arg></em></em></span></p><p><span style="color: #008080; font-size: 10pt;"><em style="color: #2a00ff; font-size: 10pt;"><em style="color: #2a00ff; font-size: 10pt;"></beans></em></em></span></p><p><span style="color: #008080; font-size: 10pt;"><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><em style="color: #2a00ff;">applicationContext.xml:</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="color: #008080; font-size: 10pt;"><? <span style="color: #3f7f7f; font-size: 10pt;">xml</span><span style="font-size: 10pt;"> </span><span style="color: #7f007f; font-size: 10pt;">version</span><span style="font-size: 10pt;">=</span><em style="color: #2a00ff; font-size: 10pt;"><em style="color: #2a00ff; font-size: 10pt;">"1.0" encoding="UTF-8"?></em></em></span></p><p><span style="color: #008080; font-size: 10pt;"><em style="color: #2a00ff; font-size: 10pt;"><em style="color: #2a00ff; font-size: 10pt;"><beans xmlns="...."></em></em></span></p><span style="color: #008080; font-size: 10pt;"><p><span style="color: #008080; font-size: 10pt;">  </span></p><span style="color: #008080; font-size: 10pt;"><p><<span style="color: #3f7f7f; font-size: 10pt;">context:annotation-config</span><span style="color: #008080; font-size: 10pt;">/></span></p></span></span></span></p><p><span style="color: #008080; font-size: 10pt;"> </span><span style="color: #008080; font-size: 10pt;"><<span style="color: #3f7f7f; font-size: 10pt;">bean</span><span style="font-size: 10pt;"> </span><span style="color: #7f007f; font-size: 10pt;">id</span><span style="font-size: 10pt;">=</span></span><em style="color: #2a00ff; font-size: 10pt;"><em style="color: #2a00ff; font-size: 10pt;">"instrService" class="com.company.business.InstrumentServiceCore"/></em></em></p><p><em><span style="color: #2a00ff; font-size: 10pt;"></span><span style="color: #2a00ff;"></beans></span></em></p><p><em style="color: #2a00ff; font-size: 10pt;"><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p></em></p><p><p align="left"><span style="font-size: 10pt; color: #2a00ff;"><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;"> </p></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>here is my Remote interface</p><p>@Remote</p><p>public interface InstrumentService{</p><p>......</p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>and i have two implementation of above InstrumentService , one is InstrumentServiceEJB and another one is InstrumentServiceCore.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p></p><p><span style="color: #008080; font-size: 10pt;">i have put beanRefContext and applicationContext.xml under META-INF/folder</span></p><p><span style="color: #008080; font-size: 10pt;"></span></p><p><span style="color: #008080; font-size: 10pt;"></span>now when i tried to call my EJB, (I am invoking my EJB through a web service call ) it throws Exception like :</p><p><span style="color: #008080; font-size: 10pt;"></span></p><p><span style="color: #008080; font-size: 10pt;"></span><span style="font-size: 10pt;"><p>javax.ejb.EJBException: java.lang.RuntimeException: org.springframework.beans.factory.access.BootstrapException: Unable to return specified BeanFactory instance: factory key [null], from group with resource name [classpath*:beanRefContext.xml]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.springframework.beans.factory.BeanFactory] is defined: expected single bean but found 0</p><p>at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:77)</p><p>at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)</p><p>at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:190)</p><p>at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)</p><p>at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)</p><p>at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)</p><p>at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)</p><p>at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)</p><p>at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:201)</p><p>at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)</p><p>at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:186)</p><p>at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)</p><p>at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)</p><p>at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)</p><p>at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)</p><p>at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)</p><p>at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)</p><p>at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)</p><p>at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:421)</p><p>at org.jboss.ejb3.remoting.IsLocalInterceptor.invokeLocal(IsLocalInterceptor.java:85)</p><p>at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:72)</p><p>at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)</p><p>at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)</p><p>at $Proxy346.invoke(Unknown Source)</p><p>at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:207)</p><p>at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:164)</p><p>at $Proxy370.browseInstruments(Unknown Source)</p><p>at com.company.rts.webservice.instrument.impl.InstrumentServiceWSImpl.browseInstruments(InstrumentServiceWSImpl.java:42)</p><p>at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)</p><p>at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)</p><p>at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)</p><p>at java.lang.reflect.Method.invoke(Method.java:597)</p><p>at org.jboss.wsf.container.jboss50.invocation.InvocationHandlerJSE.invoke(InvocationHandlerJSE.java:108)</p><p>at org.jboss.ws.core.server.ServiceEndpointInvoker.invoke(ServiceEndpointInvoker.java:222)</p><p>at org.jboss.wsf.stack.jbws.RequestHandlerImpl.processRequest(RequestHandlerImpl.java:474)</p><p>at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleRequest(RequestHandlerImpl.java:295)</p><p>at org.jboss.wsf.stack.jbws.RequestHandlerImpl.doPost(RequestHandlerImpl.java:205)</p><p>at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:131)</p><p>at org.jboss.wsf.common.servlet.AbstractEndpointServlet.service(AbstractEndpointServlet.java:85)</p><p>at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)</p><p>at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)</p><p>at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)</p><p>at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)</p><p>at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)</p><p>at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)</p><p>at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)</p><p>at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)</p><p>at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)</p><p>at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)</p><p>at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)</p><p>at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)</p><p>at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)</p><p>at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)</p><p>at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)</p><p>at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)</p><p>at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)</p><p>at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)</p><p>at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)</p><p>at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)</p><p>at java.lang.Thread.run(Thread.java:662)</p><p>Caused by: java.lang.RuntimeException: org.springframework.beans.factory.access.BootstrapException: Unable to return specified BeanFactory instance: factory key [null], from group with resource name [classpath*:beanRefContext.xml]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.springframework.beans.factory.BeanFactory] is defined: expected single bean but found 0</p><p>at org.jboss.ejb3.EJBContainer.invokeCallback(EJBContainer.java:1123)</p><p>at org.jboss.ejb3.EJBContainer.invokePostConstruct(EJBContainer.java:1133)</p><p>at org.jboss.ejb3.EJBContainer.invokePostConstruct(EJBContainer.java:1144)</p><p>at org.jboss.ejb3.pool.AbstractPool.create(AbstractPool.java:93)</p><p>at org.jboss.ejb3.InfinitePool.get(InfinitePool.java:56)</p><p>at org.jboss.ejb3.InfinitePool.get(InfinitePool.java:51)</p><p>at org.jboss.ejb3.pool.ThreadlocalPool.create(ThreadlocalPool.java:53)</p><p>at org.jboss.ejb3.pool.ThreadlocalPool.get(ThreadlocalPool.java:93)</p><p>at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:58)</p><p>at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)</p><p>at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)</p><p>... 58 more</p><p>Caused by: org.springframework.beans.factory.access.BootstrapException: Unable to return specified BeanFactory instance: factory key [null], from group with resource name [classpath*:beanRefContext.xml]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.springframework.beans.factory.BeanFactory] is defined: expected single bean but found 0</p><p>at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:409)</p><p>at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.getBeanFactoryReference(SpringBeanAutowiringInterceptor.java:156)</p><p>at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.getBeanFactory(SpringBeanAutowiringInterceptor.java:137)</p><p>at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.doAutowireBean(SpringBeanAutowiringInterceptor.java:117)</p><p>at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.autowireBean(SpringBeanAutowiringInterceptor.java:97)</p><p>at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)</p><p>at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)</p><p>at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)</p><p>at java.lang.reflect.Method.invoke(Method.java:597)</p><p>at org.jboss.ejb3.interceptors.aop.LifecycleCallbackInterceptorMethodInterceptor.invoke(LifecycleCallbackInterceptorMethodInterceptor.java:80)</p><p>at org.jboss.aop.joinpoint.ConstructionInvocation.invokeNext(ConstructionInvocation.java:79)</p><p>at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor$InvocationContext.proceed(InvocationContextInterceptor.java:138)</p><p>at org.jboss.webbeans.ejb.SessionBeanInterceptor.postConstruct(SessionBeanInterceptor.java:61)</p><p>at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)</p><p>at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)</p><p>at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)</p><p>at java.lang.reflect.Method.invoke(Method.java:597)</p><p>at org.jboss.ejb3.interceptors.aop.LifecycleCallbackInterceptorMethodInterceptor.invoke(LifecycleCallbackInterceptorMethodInterceptor.java:80)</p><p>at org.jboss.aop.joinpoint.ConstructionInvocation.invokeNext(ConstructionInvocation.java:79)</p><p>at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.setup(InvocationContextInterceptor.java:88)</p><p>at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_setup_15719768.invoke(InvocationContextInterceptor_z_setup_15719768.java)</p><p>at org.jboss.aop.joinpoint.ConstructionInvocation.invokeNext(ConstructionInvocation.java:79)</p><p>at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)</p><p>at org.jboss.aop.joinpoint.ConstructionInvocation.invokeNext(ConstructionInvocation.java:79)</p><p>at org.jboss.ejb3.EJBContainer.invokeCallback(EJBContainer.java:1119)</p><p>... 68 more</p><p>Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.springframework.beans.factory.BeanFactory] is defined: expected single bean but found 0</p><p>at org.springframework.beans.factory.BeanFactoryUtils.beanOfType(BeanFactoryUtils.java:392)</p><p>at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:400)</p><p>... 92 more</p></span></p><p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p></p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/631426#631426">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in Beginner's Corner at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>