Announcement Announcement Module
Collapse
No announcement yet.
EJB3 interceptor cannot bootstrap context Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • EJB3 interceptor cannot bootstrap context

    Hi.
    I have a annotation-based EJB3 set up with Spring autowiring :
    Code:
    @Stateless(name = "WiringExampleFacade")
    @Remote({WiringExample.class})
    @Local({WiringExample.class}) 
    @Interceptors(SpringBeanAutowiringInterceptor.class)
    public class WiringExampleFacadeEJB implements WiringExample {
    
    	// automatically injected with a matching Spring bean
        @Autowired
        private WiringExampleImpl delegate;
    My EAR contains an EJB jar (at its root). In this jar, there is a folder called context which includes a file called beanRefContext.xml; said file contains :
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/beans 
               http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
               http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-2.5.xsd">
             
         <!-- This will automatically declare several post-processors
              including the AutowiredAnnotationBeanPostProcessor -->      
         <context:annotation-config/>
         
         <import resource="classpath:businessBeans.xml" />
         
    </beans>
    If I understand things correctly, the AutoWiringInterceptor will use by default a ContextSingletonBeanFactoryLocator to retrieve the beanRefContext.xml from the classpath, so this setup should work.
    Well, it doesn't.

    Any help ?
    Last edited by sonicfab; May 9th, 2008, 02:07 PM.

  • #2
    Ok my bad on one thing :
    from the Javadoc I gather that the ContextSingletonBeanFactory locator is looking for a beanRefContext.xml file that defines a single bean of type BeanFactory.
    So here's the modified beanRefContext.xml file :
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/beans 
               http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
               http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context-2.5.xsd">
             
         <!-- This will automatically declare several post-processors
              including the AutowiredAnnotationBeanPostProcessor -->      
         <context:annotation-config/>
         
         <bean id="ejb-businesslayer.application.context" lazy-init="true"
    		class="org.springframework.context.support.ClassPathXmlApplicationContext">
    		<constructor-arg>
    			<list>
    				<value>businessBeans.xml</value>
    			</list>
    		</constructor-arg>
    	</bean>  
         
    </beans>
    That file is located inside the EJB jar that is included in my EAR, so it is in the classpath.
    But I am still getting the same error :

    java.lang.RuntimeException: org.springframework.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.springframework.beans.factory.NoSuchBeanDefini tionException: No unique bean of type [org.springframework.beans.factory.BeanFactory] is defined: expected single bean but found 0
    at org.jboss.ejb3.interceptor.LifecycleInterceptorHan dler.postConstruct(LifecycleInterceptorHandler.jav a:113)
    at org.jboss.ejb3.EJBContainer.invokePostConstruct(EJ BContainer.java:619)
    at org.jboss.ejb3.AbstractPool.create(AbstractPool.ja va:131)
    at org.jboss.ejb3.InfinitePool.get(InfinitePool.java: 49)
    at org.jboss.ejb3.ThreadlocalPool.create(ThreadlocalP ool.java:50)
    at org.jboss.ejb3.ThreadlocalPool.get(ThreadlocalPool .java:90)
    at org.jboss.ejb3.stateless.StatelessInstanceIntercep tor.invoke(StatelessInstanceInterceptor.java:54)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    at org.jboss.aspects.security.AuthenticationIntercept or.invoke(AuthenticationInterceptor.java:77)
    at org.jboss.ejb3.security.Ejb3AuthenticationIntercep tor.invoke(Ejb3AuthenticationInterceptor.java:110)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    at org.jboss.ejb3.ENCPropagationInterceptor.invoke(EN CPropagationInterceptor.java:46)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    at org.jboss.ejb3.asynchronous.AsynchronousIntercepto r.invoke(AsynchronousInterceptor.java:106)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    at org.jboss.ejb3.stateless.StatelessContainer.dynami cInvoke(StatelessContainer.java:304)
    at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:10 6)
    at org.jboss.aspects.remoting.AOPRemotingInvocationHa ndler.invoke(AOPRemotingInvocationHandler.java:82)
    at org.jboss.remoting.ServerInvoker.invoke(ServerInvo ker.java:769)
    at org.jboss.remoting.transport.socket.ServerThread.p rocessInvocation(ServerThread.java:573)
    at org.jboss.remoting.transport.socket.ServerThread.d orun(ServerThread.java:373)
    at org.jboss.remoting.transport.socket.ServerThread.r un(ServerThread.java:166)
    Caused by: org.springframework.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.springframework.beans.factory.NoSuchBeanDefini tionException: No unique bean of type [org.springframework.beans.factory.BeanFactory] is defined: expected single bean but found 0

    Comment


    • #3
      OK, MY BAD ! (again)
      The ContextSingletonBeanFactoryLocator is looking for resource classpath*:beanRefContext.xml, so the beanRefContext.xml file has to be in the classpath as the name says. I had it in a /context folder which wasn't seen by the classpath*.
      Works now !

      Comment


      • #4
        Share businessBeans.xml

        Hi, could you please share your businessBeans.xml.
        I finally can get rid of the annoying [classpath*:beanRefContext.xml] errors, but after that I can make my EJB autowired a simple test bean.
        The root exception is:
        org.springframework.beans.factory.BeanCreationExce ption:
        Autowiring of fields/methods failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption:
        Could not autowire field: private test.TestBean test.RegionServiceBean.testBean;
        nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException:
        No unique bean of type [test.TestBean] is defined:
        Unsatisfied dependency of type [class test.TestBean]:
        expected at least 1 matching bean

        So I think there is a problem with my businessBeans.xml definition.
        Thanks in advance.

        Comment


        • #5
          Basically all you have to do is to restart JBoss. Once you have deployed your jar file containing your EJBs JBoss does not reloads the classpath for your application, so if you restart your JBoss server it will read all the files contained on the root of your .jar file. So just put your refBeanContext.xml file on the root, deploy your new jar file, restart the server and you should be done.

          Comment


          • #6
            JBoss restart is necessary (JBoss EAP 6.0)

            Originally posted by oghs View Post
            Basically all you have to do is to restart JBoss. Once you have deployed your jar file containing your EJBs JBoss does not reloads the classpath for your application, so if you restart your JBoss server it will read all the files contained on the root of your .jar file.
            Apologies for resurrecting this old thread. Just dropping to say that I faced a similar issues of EJB3 Interceptors / Bootstrap context and finally issue was just about: "JBoss does not reload classpath unless restarted". on JBoss EAP 6.0

            Comment

            Working...
            X