Announcement Announcement Module
Collapse
No announcement yet.
Autowiring error with EJB 3.0 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Autowiring error with EJB 3.0

    I am trying to use the Autowiring Interceptor for EJB 3...
    Code:
    atStateless
    atInterceptors(SpringBeanAutowiringInterceptor.class)
    public class MyBean implements MyBeanLocal, MyBeanRemote
    {
    
      atAutowired
      private MyDao _myDao;
    
    ...
    }
    At root or ear file is "beanRefContext.xml"

    Code:
    ...
    <bean id="myContext" class="org.springframework.context.support.ClassPathXmlAp licationContext">
    <constructor-arg value="myContext.xml"/>
    </bean>
    ...
    Also at root of ear file is myContext.xml with a single bean definition:

    Code:
    ...
    <bean id="myDao" class="com.foo.MyDao"/>
    ...
    When I run my app I get the following:

    Code:
    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
    	at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:410)
    	at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.getBeanFactoryReference(SpringBeanAutowiringInterceptor.java:139)
    	at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.getBeanFactory(SpringBeanAutowiringInterceptor.java:120)
    	at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.autowireBean(SpringBeanAutowiringInterceptor.java:100)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:585)
    	at org.jboss.ejb3.interceptor.LifecycleInvocationContextImpl.proceed(LifecycleInvocationContextImpl.java:131)
    	at org.jboss.ejb3.interceptor.LifecycleInterceptorHandler.postConstruct(LifecycleInterceptorHandler.java:109)
    	... 71 more
    Am I missing something here? Are my config files in the correct location? I am using JBoss 4.2.2/JDK 5.0

    Thanks

  • #2
    The file cannot be found, create a directory called APP-INF/classes and put your xml files in there. Those will be automatically added to the classpath.

    Comment


    • #3
      Thanks for the prompt reply.

      My ear structure now looks like this:

      Code:
      work.ear
        - APP-INF
          - classes
            - beanRefContext.xml
            - myContext.xml
        - META-INF
          - application.xml
          - persistence.xml
        - workejb.jar
        - workweb.war
      I get the same error as before.

      The ejb class with the autowiring is in the workejb.jar along with the required spring jars.

      Thanks

      Comment


      • #4
        Make sure that the spring jars are also in the ear and not duplicated somewhere. Also your configuration looks weird/off I assume your myContext.xml needs access to the remainder of the beans in persistence etc (it is a dao you showed.).

        Can you post your whole stacktrace?

        This blog might be usefull for you. Especially the discussion in the comments about classloaders and visibility.

        Comment


        • #5
          Ok my ear structure now looks like this - It used to have the spring jars in the workejb.jar and workweb.war but now they reside at the root of the ear:

          Code:
          work.ear
            - spring jars
            - META-INF
              - application.xml
              - persistence.xml
            - workejb.jar
              - beanRefContext.xml
              - myContext.xml
            - workweb.war
          I moved the beanRefContext/myContext files to the root of the workejb.jar instead of /APP-INF/classes and it now appears to be happy. I am getting an error about my dao config but thats another issue!

          Thanks for your help

          Comment


          • #6
            Originally posted by Marten Deinum View Post
            The file cannot be found, create a directory called APP-INF/classes and put your xml files in there. Those will be automatically added to the classpath.
            APP-INF is known to WebLogic only

            Comment


            • #7
              You're right. Messed around with weblogic to long I guess .

              Main issue to solve is that you should have a jar only once on the classpath else you will run into issues.

              Comment

              Working...
              X