Saturday, March 22, 2008

Spring 2.5.1 auto wire annotation has problem working with inner class

This afternoon I ran into a problem with the new auto-wiring annotation provided by Spring 2.5.1. It seems that the @Service or @Component does not pick an annotated class if it contains an inner class. For example:

A.java

@Service
public class A{
private class B{
...
}
}


With this kind of structure, for some reason Spring annotation scanner will just simply ignore the class A in this example. For now the workaround I found is instead of using inner class, use a default scope class. For example:

A.java

@Service
public class A{
...
}

class B{
...
}


Or fall back to the old style xml bean definition for any of your service bean that contains inner class.

Currently the Spring issue tracking system is down, as soon as it comes back online I will see if this is a known issue, if not will create a issue for this problem.