I am trying to use the Spring Framework IoC Container to create an instance of class ThreadPoolExecutor.CallerRunsPolicy. In Java, I'd do it this way...
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
...
RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy();
But when I try to do the equivalent in Spring, it throws a CannotLoadBeanClassException.
<beans>
<bean class="java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy"/>
</beans>
More generally: in a Spring ApplicationContext XML, how can you call a constructor of a static inner class?
As you know Java inner classes are defined within the scope of other classes, similarly, inner beans are beans that are defined within the scope of another bean. Thus, a <bean/> element inside the <property/> or <constructor-arg/> elements is called inner bean and it is shown below.
Yes, A spring bean may have static methods too.
The container also ignores the scope flag on creation: Inner beans are always anonymous and they are always created with the outer bean. It is not possible to inject inner beans into collaborating beans other than into the enclosing bean or to access them independently.
I think the reason it is not working is because Spring is not able to understand it as a static inner class. Probably this can work:
<beans>
<bean class="java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy"/>
</beans>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With