Announcement Announcement Module
Collapse
No announcement yet.
Inner Class and @Component/@Resource not being detected. Not Supported? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    I think it's fixed (sort of - not really) in 3.1.0.M2 - see here : https://jira.springsource.org/browse/SPR-8433

    Comment


    • #3
      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.

      Comment


      • #4
        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...

        Comment


        • #5
          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.

          Comment

          Working...
          X