Spring Inner-class Instantiation

The other day I ran into something I had never tried to do with Spring before… define a bean as an instance of an inner class. I did a little searching through the Spring docs, but could not find anything about it, negative or positive. So, I just gave it a try.

Consider the class:

public abstract class IService {
    public static class ServiceImpl extends IService {
            // something useful...
    }
}

which would have a bean definition of:

<bean id="myService" class="com.some.pkg.IService$ServiceImpl" />

where the $ is the separator between the main class and the inner class. This is how its represented in the actual class file so it makes sense. Damn, I love Spring!

Average: 4.3 (3 votes)