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

  • Home
  • SEARCH
  • 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 3671816
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:32:00+00:00 2026-05-19T02:32:00+00:00

The slow autowire by type problem has finally been solved by creating a caching

  • 0

The slow autowire by type problem has finally been solved by creating a caching bean factory.

I would really like to be able to use such a CachingByTypeBeanFactory together with SpringJUnit4ClassRunner for running JUnit tests with @Autowired. But it does not seem to be possible to change the Bean Factory on the application context via the ContextLoader.

Is there any other way to do this ?

  • 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-19T02:32:00+00:00Added an answer on May 19, 2026 at 2:32 am

    Create your own ContextLoader and attach this annotation to your JUnit class:

    @ContextConfiguration(loader=YourLoader.class)
    

    This is my example Loader which instantiates another or custom ApplicationContext which in turn may be initialized with custom BeanFactory (depending of capabilities):

    public class XmlWebApplicationContextLoader extends AbstractContextLoader {
    
        public final ConfigurableApplicationContext loadContext(final String... locations) throws Exception {
            ServletContext servletContext = new MockServletContext("war", new FileSystemResourceLoader());
            GenericWebApplicationContext webContext = new GenericWebApplicationContext();
            servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webContext);
            webContext.setServletContext(servletContext);
            new XmlBeanDefinitionReader(webContext).loadBeanDefinitions(locations);        
            AnnotationConfigUtils.registerAnnotationConfigProcessors(webContext);
            webContext.refresh();
            webContext.registerShutdownHook();
            return webContext;
        }
    
        protected String getResourceSuffix() {
            return "";
        }
    

    }

    In above case application context (provided by Spring Framework) has constructor:

    public GenericWebApplicationContext(DefaultListableBeanFactory beanFactory) {
        super(beanFactory);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some slow internet task to save and load file, I'd like to
We are getting very slow compile times, which can take upwards of 20+ minutes
I refactored a slow section of an application we inherited from another company to
We have a painfully slow report.I added a Response.flush and it seems a great
The interop library is slow and needs MS Office installed. Many times you don't
Doxygen is a bit slow - it takes about a couple of minutes to
I'm wondering how slow it's going to be switching between 2 databases on every
Java was initially slow before the JIT but today performance is pretty close to
Vim is acting slow when I scroll. The cursor skips some lines when I'm
Our build is dog slow. It uses nested gnu makefiles on linux. It creates

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.