微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

AppConfig 遇到 NullPointerException 错误

如何解决AppConfig 遇到 NullPointerException 错误

更新:我下载了作者的源代码,同样的问题发生了..... pom.xml 文件> https://gist.github.com/jianheMark/09c8e250f43d436ba51d27971c4ea5a2 按照教程。但是当我运行它时,就会出现 NullPointerException 错误。我使用 Intellj。

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "cause" is null

在同一个包中的所有三个类。我已经在网上查过了。我什至注释掉了其他 xml 文件

package javaconfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class AppConfig{

    @Bean(initMethod = "customInit")
    public Customer customer(){
        return new Customer();
    }
}


public class Customer {
    public Customer() {
        System.out.println("Default Constructor.......");
    }
    public void customInit() {
        System.out.println("Customer Init......");
    }
}



package javaconfig;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class JavaConfigMain {
    public  static void main(String[] args){
       
        new AnnotationConfigApplicationContext(AppConfig.class);
    }
}

我遵循本教程:https://www.youtube.com/watch?v=0awHx-346Is&list=PLGTrAf5-F1YIUo_AWConTTY_VWGJnveT8&index=15

完整错误代码

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "cause" is null
    at org.springframework.cglib.core.CodeGenerationException.<init>(CodeGenerationException.java:25)
    at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:587)
    at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:363)
    at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:585)
    at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:110)
    at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:108)
    at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61)
    at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
    at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:134)
    at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:319)
    at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:572)
    at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:419)
    at org.springframework.context.annotation.ConfigurationClassEnhancer.createClass(ConfigurationClassEnhancer.java:137)
    at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:109)
    at org.springframework.context.annotation.ConfigurationClasspostProcessor.enhanceConfigurationClasses(ConfigurationClasspostProcessor.java:447)
    at org.springframework.context.annotation.ConfigurationClasspostProcessor.postProcessbeanfactory(ConfigurationClasspostProcessor.java:268)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokebeanfactoryPostProcessors(PostProcessorRegistrationDelegate.java:325)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokebeanfactoryPostProcessors(PostProcessorRegistrationDelegate.java:147)
    at org.springframework.context.support.AbstractApplicationContext.invokebeanfactoryPostProcessors(AbstractApplicationContext.java:746)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564)
    at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:93)
    at javaconfig.JavaConfigMain.main(JavaConfigMain.java:12)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。