Spring Inner-Class Instantiation

13 July 2005 ~ blog java spring

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. Nice.


Creative Commons License CoffeaElectronica.com content is copyright © 2016 Christopher J. Stehno and available under a Creative Commons Attribution-ShareAlike 4.0 International License.