Results 1 to 5 of 5

Thread: Inner Class and @Component/@Resource not being detected. Not Supported?

  1. #1

    Default Inner Class and @Component/@Resource not being detected. Not Supported?

    Hi,

    Spring 3.0.5
    Java 1.6u25

    Here's a little example:

    Code:
    @Component("daoFactory")
    public class DaoFactory {
    
        @Autowired
        private ApplicationContext applicationContext;
    
        public TestDao getTestDao() {
            return applicationContext.getBean("test", TestDaoImpl.class);
        }
    
        @Repository("test")
        public class TestDaoImpl extends AbstractDao<Model> implements TestDao {
    
            public TestDaoImpl() {
                super(Model.class);
            }
    
            @Override
            public Model create() {
                return null;
            }
    
        }
    
    }
    When I execute a simple unit test to see if a TestDao is returned, I get this:

    Code:
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'test' is defined
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:527)
    In my applicationContext-testing.xml, I have this:

    Code:
    <context:component-scan base-package="uk.foo.bar" />
    Any idea why the inner class isn't being autodetected and added to the BeanFactory? If I could get this solved, I could remove a chunk of duplicate code :-)

    Thanks!

    -=david=-

  2. #2

    Default

    I think it's fixed (sort of - not really) in 3.1.0.M2 - see here : https://jira.springsource.org/browse/SPR-8433

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

    Default

    And why should it be able to check for a non-static inner class?! The class cannot exist without its enclosing class, if it would be static it might be possible to do so, but I guess not for non-static inner classes.
    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

  4. #4

    Default

    Granted it can't exist without the enclosing class, but seems strange that Spring can create the enclosing class bean, then not also associate the inner class bean with a bean factory...

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

    Default

    That is something that (if I'm not mistaken) doesn't even work with plain xml it will only work in xml with a static inner bean not non-static inner-beans.
    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
  •