环境信息
-
dubbo 2.6.5
-
spring-boot-starter-quartz 2.0.6.RELEASE
-
spring boot 2.0.6.RELEASE
NPE错误信息
org.quartz.SchedulerException: Job instantiation failed at org.springframework.scheduling.quartz.AdaptableJobFactory.newJob(AdaptableJobFactory.java:47) ~[spring-context-support-5.0.10.RELEASE.jar:5.0.10.RELEASE] at org.quartz.core.JobRunShell.initialize(JobRunShell.java:127) ~[quartz-2.3.0.jar:na] at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:392) [quartz-2.3.0.jar:na] Caused by: java.lang.NullPointerException: null at com.alibaba.dubbo.config.spring.beans.factory.annotation.DubboConfigBindingBeanPostProcessor.postProcessBeforeInitialization(DubboConfigBindingBeanPostProcessor.java:79) ~[dubbo-2.6.5.jar:2.6.5] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:416) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1686) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:407) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE] at org.springframework.boot.autoconfigure.quartz.AutowireCapableBeanJobFactory.createJobInstance(AutowireCapableBeanJobFactory.java:45) ~[spring-boot-autoconfigure-2.0.6.RELEASE.jar:2.0.6.RELEASE] at org.springframework.scheduling.quartz.AdaptableJobFactory.newJob(AdaptableJobFactory.java:43) ~[spring-context-support-5.0.10.RELEASE.jar:5.0.10.RELEASE] ... 2 common frames omitted
NullPointerException 原因分析
spring-boot-autoconfigure-2.0.2.RELEASE.jar->AutowireCapableBeanJobFactory.java
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception { Object jobInstance = super.createJobInstance(bundle); this.beanFactory.autowireBean(jobInstance); this.beanFactory.initializeBean(jobInstance, (String)null); return jobInstance; }
注意,上面创建job实列时候,赋值的bean的name为
`null
dubbo-2.6.5.jar>DubboConfigBindingBeanPostProcessor.java
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (beanName.equals(this.beanName) && bean instanceof AbstractConfig) { AbstractConfig dubboConfig = (AbstractConfig)bean; this.bind(this.prefix, dubboConfig); this.customize(beanName, dubboConfig); } return bean; }
提示,dubbo在使用beanName的时候未作空验证,导致NullPointerException
解决办法
根据dubbo的说法升级spring boot 版本,参考https://github.com/apache/dubbo/issues/2429
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.5.RELEASE</version> <relativePath/> </parent>
测试通过,升级到
2.1.9.RELEASE
,2.1.18.RELEASE
,2.3.5.RELEASE
application.properties 文件增加配置
spring.main.allow-bean-definition-overriding=true提示:如果application.properties文件不添加上方配置可能在启动时候报错当dubbo版本为(2.6.9)时候,2.6.5版本不会
原创文章,作者:3628473679,如若转载,请注明出处:https://blog.ytso.com/243794.html