Beanfactory not initialized or already closed-call ' refresh ' before access

Source: Internet
Author: User
Exception in thread "main" java.lang.IllegalStateException: beanfactory not initialized or already closed-call ' REFR Esh ' before accessing beans via the ApplicationContext

When encountering this kind of error, many people on the Internet are advised to solve this problem:

Beanfactory is not instantiated or has been closed, in fact, the cause of the error is very simple, in writing:

ApplicationContext CTX = new Classpathxmlapplicationcontext ();

, when the configuration file is not specified, spring instantiates beanfactory by default to Classpath to find the file named Applicationcontext.xml, but you do not specify it, so this error occurs.

This is the reason for the error, the name of the file in parentheses to write the line.

ApplicationContext CTX = new Classpathxmlapplicationcontext ("Applicationcontext.xml");

In that case, there would be no such mistake.

But there are other reasons for the error:

This error is also reported when your control layer controller file has duplicate names.

Beanfactory not initialized or already closed-call ' refresh ' before access

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.