Any existing way to make sure beans defined in spring xml are stateless?
Working on a large size project, we started to use spring to manage our dependency injection. Since most dev are migrate from coding stateful class, 开发者_Go百科we found some of stateless bean actually contain instance variables which themself are stateful.
Correct me if I am wrong, it shouldn't be too tough to write a unit test to verify that all the stateless bean defined in spring xml actually is stateless (i.e. bean shouldn't have any instance variable which never defined in spring xml). Before I will try myself to write one, wonder if there is any existing tool out there to check that?
Thx
Check out spring context analyzer. It detects a few of the common spring scope/wiring mistakes, including missing scope proxies and suspicious post-construct field state in your beans. I know many projects have been saved by it ;)
精彩评论