hot swapping spring beans

97 views
Skip to first unread message

Michael Wiles

unread,
Nov 26, 2010, 3:47:34 AM11/26/10
to CTJUG...@googlegroups.com
All you spring gurus...

I wish to test my spring application and to do this I need to mock out certain spring beans. I do not want to create a whole new spring context to do this, nor do I want to move away from using annotations.

So I would like to do the following:

Use the normal spring unit test mechanisms to setup my test
@RunWith(SpringJUnit4ClassRunner.class) and @ContextConfiguration

And then for each test to create the mock version of the bean it wants to mock and then hot swap that bean in. When the test is done put the original bean back.

It can be done, it is talked about here.

There is the org.springframework.aop.target.HotSwappableTargetSource which allows for the hot swapping of one bean with another.

The problem is how do I configure a bean for hot swapping via annotations? According to all the documentation I've read, I just annotate with @Aspect - I must be missing a trick as this doesn't work.

Anyone done something similar or can help?

Reply all
Reply to author
Forward
0 new messages