Announcement Announcement Module
Collapse
No announcement yet.
defining inner classes as spring beans? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • defining inner classes as spring beans?

    Hi,

    I have problems configuring static inner classes in a spring context.
    Are inner classes supported for being defined as spring beans?

    When I access an instance of an inner class through a BeanFacctory, I get a ClassNotFoundException, while I can instantiate that static inner class by using new.

    Here are the details:
    org.springframework.beans.factory.BeanDefinitionSt oreException: Error registering bean with name 'inner' defined in class path resource [context.xml]: Bean class [innerbeans.Outer.Inner] not found; nested exception is java.lang.ClassNotFoundException: innerbeans.Outer.Inner
    java.lang.ClassNotFoundException: innerbeans.Outer.Inner

    I'm using spring 1.2.5.

    The context is configured as follows:
    Code:
    <beans>
    
        <bean id="outer" class="innerbeans.Outer">
            <property name="outername" value="helloouter"/>
        </bean>
        <bean id="inner" class="innerbeans.Outer.Inner">
            <property name="innername" value="helloinner"/>
        </bean>
    
    </beans>
    The bean is defined as:
    Code:
    package innerbeans;
    
    public class Outer {
        private String outername;
    
        public Outer() {
        }
    
        public void setOutername(String outername) {
            this.outername = outername;
        }
    
        public static class Inner {
            private String innername;
    
            public Inner() {
            }
    
            public void setInnername(String innername) {
                this.innername = innername;
            }
        }
    }

  • #2
    Hi,

    try
    Code:
        
    ...
    <bean id="inner" class="innerbeans.Outer$Inner">
            <property name="innername" value="helloinner"/>
    </bean>
    regards

    Mario

    Comment


    • #3
      That works fine .

      Thank you,
      Uli

      Comment

      Working...
      X