遇到个很诡异的问题,困扰了我好几天,项目运行不起来导致我无法开发下去。

问题描述:这是个Spring Boot个人项目,从环境的搭建到开发这一过程还是挺顺利的,其中遇到的问题也都解决了,也做了相应的记录,具体可以翻阅我之前的博客,可能有些问题没有记录下来,望谅解。
突然发现使用springboot内嵌的服务器时,有些麻烦的地方,就是每次更改项目中的java等文件时,都要全量打包,如果要使用增量打包的话,则必须使用第三方的应用服务器(Tomcat服务器)。就在使用外部的tomcat服务器部署的时候,就遇到了jar包冲突或找不到相应的类的异常(如,ELManager)。网上也有很多此类的解决方案,可以参考网上的。接下来我所说的是另一个问题,网上很少有这个答案。
当我用IDEA启动springboot项目时,发现报了以下异常:

2019-01-01 10:42:17.407 INFO 26196 — [ main] com.example.demo.DemoApplication : Starting DemoApplication on guyuanhui with PID 26196 (E:\guyuanhui\NewGraduateProject\xiaoyiduo\test1\target\classes started by guyuanhui in E:\guyuanhui\NewGraduateProject\xiaoyiduo\test1)
2019-01-01 10:42:17.411 INFO 26196 — [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2019-01-01 10:42:17.477 INFO 26196 — [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@482cd91f: startup date [Tue Jan 01 10:42:17 CST 2019]; root of context hierarchy
2019-01-01 10:42:18.664 WARN 26196 — [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor’: Invocation of init method failed; nested exception is java.lang.IllegalAccessError: javax/el/Util
2019-01-01 10:42:18.673 INFO 26196 — [ main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
2019-01-01 10:42:18.684 ERROR 26196 — [ main] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor’: Invocation of init method failed; nested exception is java.lang.IllegalAccessError: javax/el/Util
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1710) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:583) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean0(AbstractBeanFactory.java:312) [spring−beans−5.0.4.RELEASE.jar:5.0.4.RELEASE]atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) [spring−beans−5.0.4.RELEASE.jar:5.0.4.RELEASE]atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) [spring−beans−5.0.4.RELEASE.jar:5.0.4.RELEASE]atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:205) [spring−beans−5.0.4.RELEASE.jar:5.0.4.RELEASE]atorg.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:205) [spring−context−5.0.4.RELEASE.jar:5.0.4.RELEASE]atorg.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:709) [spring−context−5.0.4.RELEASE.jar:5.0.4.RELEASE]atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:534) [spring−context−5.0.4.RELEASE.jar:5.0.4.RELEASE]atorg.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) [spring−boot−2.0.0.RELEASE.jar:2.0.0.RELEASE]atorg.springframework.boot.SpringApplication.refresh(SpringApplication.java:752)[spring−boot−2.0.0.RELEASE.jar:2.0.0.RELEASE]atorg.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:388)[spring−boot−2.0.0.RELEASE.jar:2.0.0.RELEASE]atorg.springframework.boot.SpringApplication.run(SpringApplication.java:327)[spring−boot−2.0.0.RELEASE.jar:2.0.0.RELEASE]atorg.springframework.boot.SpringApplication.run(SpringApplication.java:1246)[spring−boot−2.0.0.RELEASE.jar:2.0.0.RELEASE]atorg.springframework.boot.SpringApplication.run(SpringApplication.java:1234)[spring−boot−2.0.0.RELEASE.jar:2.0.0.RELEASE]atcom.example.demo.DemoApplication.main(DemoApplication.java:10)[classes/:na]Causedby:java.lang.IllegalAccessError:javax/el/Utilatjavax.el.ELManager.getExpressionFactory(ELManager.java:30) [tomcat−embed−el−8.5.28.jar:2.2.FR]atorg.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.buildExpressionFactory(ResourceBundleMessageInterpolator.java:88) [hibernate−validator−6.0.7.Final.jar:6.0.7.Final]atorg.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.&lt;init&gt;(ResourceBundleMessageInterpolator.java:47) [hibernate−validator−6.0.7.Final.jar:6.0.7.Final]atorg.hibernate.validator.internal.engine.ConfigurationImpl.getDefaultMessageInterpolator(ConfigurationImpl.java:461) [hibernate−validator−6.0.7.Final.jar:6.0.7.Final]atorg.springframework.boot.validation.MessageInterpolatorFactory.getObject(MessageInterpolatorFactory.java:54) [spring−boot−2.0.0.RELEASE.jar:2.0.0.RELEASE]atorg.springframework.boot.context.properties.ConfigurationPropertiesJsr303Validator0(AbstractBeanFactory.java:312) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:205) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:205) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:709) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:534) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:388) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1234) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] at com.example.demo.DemoApplication.main(DemoApplication.java:10) [classes/:na] Caused by: java.lang.IllegalAccessError: javax/el/Util at javax.el.ELManager.getExpressionFactory(ELManager.java:30) ~[tomcat-embed-el-8.5.28.jar:2.2.FR] at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.buildExpressionFactory(ResourceBundleMessageInterpolator.java:88) ~[hibernate-validator-6.0.7.Final.jar:6.0.7.Final] at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.&lt;init&gt;(ResourceBundleMessageInterpolator.java:47) ~[hibernate-validator-6.0.7.Final.jar:6.0.7.Final] at org.hibernate.validator.internal.engine.ConfigurationImpl.getDefaultMessageInterpolator(ConfigurationImpl.java:461) ~[hibernate-validator-6.0.7.Final.jar:6.0.7.Final] at org.springframework.boot.validation.MessageInterpolatorFactory.getObject(MessageInterpolatorFactory.java:54) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] at org.springframework.boot.context.properties.ConfigurationPropertiesJsr303Validator0(AbstractBeanFactory.java:312) [springbeans5.0.4.RELEASE.jar:5.0.4.RELEASE]atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) [springbeans5.0.4.RELEASE.jar:5.0.4.RELEASE]atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) [springbeans5.0.4.RELEASE.jar:5.0.4.RELEASE]atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:205) [springbeans5.0.4.RELEASE.jar:5.0.4.RELEASE]atorg.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:205) [springcontext5.0.4.RELEASE.jar:5.0.4.RELEASE]atorg.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:709) [springcontext5.0.4.RELEASE.jar:5.0.4.RELEASE]atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:534) [springcontext5.0.4.RELEASE.jar:5.0.4.RELEASE]atorg.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) [springboot2.0.0.RELEASE.jar:2.0.0.RELEASE]atorg.springframework.boot.SpringApplication.refresh(SpringApplication.java:752)[springboot2.0.0.RELEASE.jar:2.0.0.RELEASE]atorg.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:388)[springboot2.0.0.RELEASE.jar:2.0.0.RELEASE]atorg.springframework.boot.SpringApplication.run(SpringApplication.java:327)[springboot2.0.0.RELEASE.jar:2.0.0.RELEASE]atorg.springframework.boot.SpringApplication.run(SpringApplication.java:1246)[springboot2.0.0.RELEASE.jar:2.0.0.RELEASE]atorg.springframework.boot.SpringApplication.run(SpringApplication.java:1234)[springboot2.0.0.RELEASE.jar:2.0.0.RELEASE]atcom.example.demo.DemoApplication.main(DemoApplication.java:10)[classes/:na]Causedby:java.lang.IllegalAccessError:javax/el/Utilatjavax.el.ELManager.getExpressionFactory(ELManager.java:30) [tomcatembedel8.5.28.jar:2.2.FR]atorg.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.buildExpressionFactory(ResourceBundleMessageInterpolator.java:88) [hibernatevalidator6.0.7.Final.jar:6.0.7.Final]atorg.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.<init>(ResourceBundleMessageInterpolator.java:47) [hibernatevalidator6.0.7.Final.jar:6.0.7.Final]atorg.hibernate.validator.internal.engine.ConfigurationImpl.getDefaultMessageInterpolator(ConfigurationImpl.java:461) [hibernatevalidator6.0.7.Final.jar:6.0.7.Final]atorg.springframework.boot.validation.MessageInterpolatorFactory.getObject(MessageInterpolatorFactory.java:54) [springboot2.0.0.RELEASE.jar:2.0.0.RELEASE]atorg.springframework.boot.context.properties.ConfigurationPropertiesJsr303ValidatorDelegate.(ConfigurationPropertiesJsr303Validator.java:71) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.context.properties.ConfigurationPropertiesJsr303Validator.(ConfigurationPropertiesJsr303Validator.java:43) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.context.properties.ConfigurationPropertiesJsr303Validator.getIfJsr303Present(ConfigurationPropertiesJsr303Validator.java:64) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.context.properties.ConfigurationPropertiesBinder.(ConfigurationPropertiesBinder.java:69) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.afterPropertiesSet(ConfigurationPropertiesBindingPostProcessor.java:78) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1769) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1706) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
… 16 common frames omitted

令我很诧异的是,我IDEA上的代码都没有改动过,我处理的都是外部tomcat的jar包的问题。为什么在IDEA上会突然跑不起来了呢,之前还是可以正常启动的啊!为了解决这个问题,各种方式都使用过了。暴力法:重装IDEA,更改系统变量中指定新的jdk和IDEA下的maven,重新拉取最新版本的项目,更换内嵌的Tomcat版本,再运行,还是这个异常。

问题排查:尝试在另一台电脑上运行此项目,发现可以正常跑起来!可见项目源代码是没有问题的。回到本机,创建了个springboot的demo,发现还是这个问题。所以十分肯定,问题就出在环境上。

最终解决方案。启动项目,发觉到控制台输出的第一行的jdk路径不对,还是原先的。我明明安装了新的jdk并且在系统变量也配置了啊。后来重新引入新的jdk,最后成功跑起来了。可见,问题就出现在jdk身上。

出错原因:为了解决外部tomcat部署springboot项目的问题,根据网上提供的方案,在替换相关的jar包时,可能不小心将jdk中的jar包替换了。所以导致了该异常。除了这个,我找不到其他的原因了,因为之前都是好好的。

总结:为了解决一个小问题,参考了网上的解决方案而引出了其他难以解决的bug。这时可能会考虑极端的解决方法,而在采用极端的方法时,需要检验每一步是否准确无误了,否则后面就不会再回头考虑刚才的极端方法。然而这恰恰是最好的方案。

Logo

聚焦前沿AI与大模型技术探索,汇聚开发者及爱好者,共享开源项目、学习资源与行业资讯。

更多推荐