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 8690059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:49:10+00:00 2026-06-12T23:49:10+00:00

I have two beans of the same name and same class. I want to

  • 0

I have two beans of the same name and same class. I want to mock (mocking is not done through @Mock annotation but done in the Spring file because of some reason) one of them and leave the other one as normal (used for integration tests).

One way, I could think of is to change resource file in @ContextConfiguration's location attribute and load separate configs for unit testing and integration testing.

Is there any other way to accomplish this task?

I understand that there are some issues like Why not to use @Mock?, Why to have two beans of same class and same bean? but I cannot change that because some part is already there and I don’t want to change that.

Thanks,

  • 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-06-12T23:49:12+00:00Added an answer on June 12, 2026 at 11:49 pm

    I have separate configuration files when necessary for different purposes. One scenario is one for testing and another for production. I agree with your first thought.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create two beans of the same class through xml config file.
I have two spring beans as follows: @Component(A) @Scope(prototype) public class A extends TimerTask
I have two beans which comes from the same class(id1 and id2), the difference
I have two beans, beanA and beanB , in my Spring config. Both of
i have a problem with spring autowire feature which found two beans with the
I have two beans that are structured exactly the same. I pull both those
I have two Service classes which implement the same interface ServiceClass1 @Service public class
I have two almost identical Beans. Bean Item contains a unique identifier (primary key),
I'm creating an application which works on Froyo until Jelly Beans. I have two
I have two classes (MVC view model) which inherits from one abstract base class.

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.