Org. springframework. beans. factory. support. DefaultListableBeanFactory in Spring. solution.

Source: Internet
Author: User
 

[Original article, reprinted, please specify the source]

It took a lot of time to configure Spring.

First install a Spring IDE for Eclipse EE

Then download the Spring framework 3.0.6 http://www.springframework.org/

We found many dependency packages and found them on CSDN, which are all dependencies of Spring 3.0.5:
Http://download.csdn.net/detail/lzgame/3548052, a total of 8 packages

Now we need to add Spring framework and these dependency packages to the project. I made them into a User Library, as shown in figure

Do not selectSystem library (added to the boot class path)This item. Otherwise, an error will be reported during running. I will talk about it later.

Add them to the project, as shown in figure

After adding the program, you can run a simple program (the main program is shown below)

 

publicclassTestBatch{    private static ApplicationContext context;    @SuppressWarnings("unchecked")    publicstaticvoid main(finalString[] args){            context =newClassPathXmlApplicationContext("/META-INF/spring/applicationContext.xml");            try{                @SuppressWarnings("unused")                TestBatch app =newTestBatch();            }catch(Exception ex){                ex.printStackTrace();            }    }    publicvoidTestBatch(){/** Do Something using the context **/}}

Output: Hello!
How are you?

However, this process encountered some trouble. I checkedSystem library (added to the boot class path ),The following error occurs:

 

 

Is caused here:

Caused by: java. lang. NullPointerException
At org. springframework. beans. factory. support. DefaultListableBeanFactory. <clinit> (defalistlistablebeanfactory. java: 106)
... 7 more

The source code is as follows:

static{    ClassLoader cl =DefaultListableBeanFactory.class.getClassLoader();    try{        javaxInjectProviderClass = cl.loadClass("javax.inject.Provider");//Line 106    }    catch(ClassNotFoundException ex){        // JSR-330 API not available - Provider interface simply not supported then.    }}

Source code problems are:

ClassLoader
Cl = defalistlistablebeanfactory. class. getClassLoader (); return null!

I found the Internet: I found someone else has encountered the following:

Http://stackoverflow.com/questions/2272354/why-do-i-get-a-nullpointerexception-when-initializing-spring

Let's take a look at the principle of getClassLoader:

Http://blog.chenlb.com/2009/06/java-classloader-architecture.html

It turns out that the DefaultListableBeanFactory is directly loaded through BootStrap. When getClassLoader () is returned, null is returned.

JDK also describes:

"Public ClassLoaderGetClassLoader() Returns the Class Loader for this class. Some implementations may use null to indicate the bootstrap loader. If the class is loaded by the bootstrap loader, this method returns null in this implementation. "

I thought it was a mistake here: I checkedSystem library (added to the boot class path ),DefaultListableBeanFactory is directly loaded as a system Jar through BootStrap.

Just tick this one.

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.