Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

How to use different application context for JUnit versus regular execution

Avatar of Jeth01
Jeth01 asked on
SoftwareJavaJava EE
6 Comments1 Solution1191 ViewsLast Modified:
Hi,

I have some mock DAOs that I created for some JUnits. I have them autowired with a separate application context file. (They are in a different package and I'm using the component scan) They just return dummy objects instead of fetching from the database. The regular DAOs are through hibernate.
My problem is, I can't figure out how to tell Spring to use that file when running JUnits, and to use the regular XML file otherwise. I want the JUnits to run with the mock DAOs, so we don't need a DB for those. But then when running the application normally, use the real DAOs.
I am fairly new to Spring so this is all a learning experience for me. Any help would be appreciated. Thanks.
One other thing -- I have them in a separate file because they are the same names as the regular DAOs, so that nothing else has to change. But if there is a way to tell Spring to only load the mock ones, or to only use the mock ones for JUnit, then I don't need the separate file.
ASKER CERTIFIED SOLUTION
Avatar of anilallewar
anilallewarFlag of India image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answers