Results 1 to 7 of 7

Thread: Autowiring error with EJB 3.0

  1. #1
    Join Date
    Aug 2008
    Posts
    3

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Aug 2008
    Posts
    3

    Default

    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

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Aug 2008
    Posts
    3

    Default

    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

  6. #6
    Join Date
    Dec 2005
    Posts
    5

    Default

    Quote 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

  7. #7
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •