问题遇到的现象和发生背景
同样一套代码,基于springboot2.3.12开发,在linux和windows系统上使用相同版本的JDK和maven编译打包,放在linux机器上启动,windows系统打包的jar能正常启动,linux系统打包的jar启动报错,错误描述是bean找不到。两个jar包的大小不一致,但差距不大,Linux打包的jar大小为117135618字节,windows系统打包的jar大小为117135630字节。通过jar包比较工具比较两个包没有发现区别,提问:Linux系统和windows系统编译打包过程有什么区别?
遇到的现象和发生背景,请写出第一个错误信息
java.lang.NullPointerException: null
org.springframework.beans.factory.BeanCreationException
用代码块功能插入代码,请勿粘贴截图。 不用代码块回答率下降 50%
linux编译打包的代码启动时报错,通过以下形式的代码获取不到bean
public class SpringUtil implements ApplicationContextAware{ ...}
Map<String, Object> beans = SpringUtil.getApplicationContext().getBeansWithAnnotation(Mapper.class);
运行结果及详细报错内容
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:160) ~[spring-beans-5.2.15.RELEASE.jar!/:5.2.15.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:415) ~[spring-beans-5.2.15.RELEASE.jar!/:5.2.15.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1791) ~[spring-beans-5.2.15.RELEASE.jar!/:5.2.15.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.15.RELEASE.jar!/:5.2.15.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.15.RELEASE.jar!/:5.2.15.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.15.RELEASE.jar!/:5.2.15.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.15.RELEASE.jar!/:5.2.15.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.15.RELEASE.jar!/:5.2.15.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.15.RELEASE.jar!/:5.2.15.RELEASE]
我的解答思路和尝试过的方法,不写自己思路的,回答率下降 60%
最初怀疑过windows和Linux上安装的JDK,maven版本不一致,后来尝试统一版本问题仍然没有解决。
后来怀疑git克隆到linux和windows的代码不一致,后来统一使用一套源代码分别放在linux和windows编译打包,问题仍然没有解决。
再者怀疑linux系统编译打包时和windows编码不同或者类加载顺序不同,由于缺乏相关的知识和经验,目前没办法求证。
请大家回答我的疑惑或者提供解决问题的思路,谢谢!