From: Michael Youngstrom <youngm@gm...> - 2006-07-01 04:50:30
> Unit testing classes with static state is more difficult than those with
> purely instance state because you have to explicitly clean up the state in a
> tearDown() method or else risk impacting another test.
That's a good point. Correct me if I'm wrong but another reason might
be that you could never create two bean definitions using the same
class with different injected singletons within the same ClassLoader
level. Any sub classes of the class would have the same problem.
>But, in this case,
> injecting statics is a lot simpler than employing AOP proxies and cleaner
> than requiring a static reference to your container (so you can re-inject
> values upon deserialization).
I don't necessarily think the AOP proxy approach is all that ugly or
complex. :) The functionality to do exactly this already exists with
<aop:scoped-proxy/> for request and session scoped beans for some of
the exact same reasons you need this support for singletons. Oh well,
it was just a thought.