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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:53:28+00:00 2026-06-16T13:53:28+00:00

I have created 2 classes A,B for JUnit, each has its own ContextLoaders for

  • 0

I have created 2 classes A,B for JUnit, each has its own ContextLoaders for loading the application context. Now when I run each of these classes independently the JUnit test run fine.

But when I do a maven build or run the JUnit on both of these classes the one which runs first say A, runs perfectly fine but the second one throws an exception (could not autowire field….expected one found none…). here is what i’m trying to do:-

//Class A with Context loader A_ContextLoader

@runwith(springjunit4classrunner.class)
@ContextConfiguration(loader = A_ContextLoader.class)
public class A {
     @Test
     public void testMethod1() {
       ...
     }
}

//Class B with Context loader B_ContextLoader

@runwith(springjunit4classrunner.class)
@ContextConfiguration(loader = B_ContextLoader.class)
public class B {
     @Test
     public void testMethod2() {
        ...
     }
}

From what I understand, when the execution starts for the 2nd class it uses the existing context instead of initializing a new one. In my case it is not possible that i club both the context loaders into a single class.

So is there some way I can “unload” the application context at the end of execution of class A. Or some how ask JUnit to reinitialize the context when execution for B starts? Or Am I missing out something?

  • 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-16T13:53:29+00:00Added an answer on June 16, 2026 at 1:53 pm

    In an first workaround, try to add @DirtiesContext to the testes. Then the Context of this annotated testes get not been uses afterwards in an other test.

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

Sidebar

Related Questions

I have created a project that uses scala that has some abstract classes definitions
I have created 3 classes. Each of them extends Overlay. And each of them
I have created 3 classes as following Ext.mine.TextParent - Inherting from Textfield Ext.mine.child.TextChildA -
I have created 2 classes as follows... public class A extends JFrame { public
I have created two viewController classes such that one is superclass of another.i have
I have created a jar file of few of my classes and preverified them
Say I have two classes created work and workItem. CWorker *work = new CWorker();
After I have created a serious bunch of classes (with initialize methods), I am
I have created a class derived from NSImageView. However, the classes's constructor (init) is
I am trying to implement my persitent classes using interfaces. I have created the

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.