Java – Using static nested class as Spring bean

inner-classesjavaspring

How do I create an instance of a static nested class as a Spring bean in an XML configuration file?
For example:

package com.x.y;
public class A {
    public static class B {
    ...
    }
}

So that I have a Spring-managed bean of class B?

Best Answer

Using A$B syntax, which is how the classloader sees inner classes. So assuming package com.x.y, then:

<bean id="myBean" class="com.x.y.A$B"/>