Why do I get a NullPointerException when initializing Spring

前端 未结 4 1320
再見小時候
再見小時候 2021-01-19 15:53

I\'ve got a problem running a batch job on my server, whereas it runs fine from Eclipse on my development workstation.

I\'ve got my Spring environment set up using R

4条回答
  •  孤城傲影
    2021-01-19 16:23

    The cause of problem is -Djava.endorsed.dirs=$PROJECTHOME/target/lib org.springframework.beans.factory.support.DefaultListableBeanFactory contains the following code:

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

    It causes a NullPointerException, because getClassLoader() returns null when class is loaded via -Djava.endorsed.dirs. From javadoc:

    Some implementations may use null to represent the bootstrap class loader.

    So, use -classpath (with explicit specification of all jars) instead of -Djava.endorsed.dirs

提交回复
热议问题