Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3458048
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:56:06+00:00 2026-05-18T09:56:06+00:00

I know similar questions have been asked, e.g. here , but having done a

  • 0

I know similar questions have been asked, e.g. here, but having done a search, I’ve come upon a solution I’m much happier with here

My only problem however, is that I’m not sure how to implement this solution.

What I want to be able to do is via the HotswappableTargetSource override the bean definitions of select beans in my application context with my test versions and then run the test.

Then for each test case I’d like to specify which beans I want to be hot swappable and then each test must be able to create its own mock versions and swap those in, and be able to swap back again.

I am able to get the Application Context the test is running with but what I don’t know is how to configure a bean to be hot swappable. I know how to do it when configuring beans with xml but I don’t want to go back to using xml to configure beans.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:56:07+00:00Added an answer on May 18, 2026 at 9:56 am

    UPDATE: There’s a library that does it!

    https://bitbucket.org/kubek2k/springockito/wiki/springockito-annotations

    The solution is as follows:

    You will need to change the spring context of your application to proxy the bean you want to swap:

    <bean id="beanSwappable" class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="targetSource" ref="beanSwap" />
    </bean>
    
    <bean id="beanSwap" class="org.springframework.aop.target.HotSwappableTargetSource">
        <constructor-arg ref="beanToSwap" />
    </bean>
    
    • beanSwap is the proxy onto this beanSwap.
    • beanSwappable is the bean which you reference when you want to swap the bean
    • beanToSwap is the default implementation of the bean

    Thus a change to the system under test is necessary.

    And in your test the code will look like:

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations = { "test.xml", "spring.xml" })
    public class Test {
    
        @Resource(name="beanSwappable")
        Bean b;
    
        @Resource(name = "beanSwap")
        HotSwappableTargetSource beanSwap;
    
        public void swap() {
            Bean b = << create mock version >>
            beanSwap.swap(b);
            // run test code which
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Various incarnations of this question have been asked here before, but I thought I'd
I know I have already answered a similar question ( Running Batch File in
I know this is similar to this question , but I'm using SQL Server
I have two computers. Both running WinXP SP2 (I don't really know ho similar
My background is primarily as a Java Developer, but lately I have been doing
This is very similar to a question I asked the other day but my
I have an interesting problem here I've been trying to solve for the last
This question was inspired by a similar question: How does delete[] know the size
Does anyone know of a similar product to Citrix Server that'll run on the
Do you know any libraries similar to java.util.Properties that support more advanced features like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.