千万不要用压缩软件打包jar包,特别是springboot项目的jar包

七海恋空 2021-02-06 浏览(0 评论(0

最近接触的公司产品是基于springboot框架的微服务,我想在本地部署一下,结果各种大坑小坑踩了个遍。docker、springboot、postgresql各种各样的新东西,完全都没有接触过。部署之前,我还一个劲的在找tomcat在哪里呢?部署完也是各种报错,百度都快被我度烂了。

耗了一个多星期,springboot项目还是一启动就报错。数据库问题、网络问题、系统问题、配置文件问题、协助应用问题我排查和解决了一系列问题,最后报错日志终于稳定下来了。

2021-01-31 23:27:31,079 WARN o.s.c.s.AbstractApplicationContext [main]: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'propertyAccessorBeanPostProcessor' defined in class path resource [org/springframework/cloud/stream/config/BindingServiceConfiguration$PostProcessorConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'metaDataSourceAdvisor': Cannot resolve reference to bean 'methodSecurityMetadataSource' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration': BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.annotation.ProxyCachingConfiguration': BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.jcache.config.ProxyJCacheConfiguration': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error the @annotation pointcut expression is only supported at Java 5 compliance level or above

2021-01-31 23:27:31,085 ERROR o.s.b.f.s.DefaultSingletonBeanRegistry [main]: Destroy method on bean with name 'org.springframework.context.annotation.internalScheduledAnnotationProcessor' threw an exception

java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@64a896b0: startup date [Sun Jan 31 23:27:25 EST 2021]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@101952da

 

2021-01-31 23:27:31,094 ERROR o.s.b.f.s.DefaultSingletonBeanRegistry [main]: Destroy method on bean with name 'org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor' threw an exception

java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@64a896b0: startup date [Sun Jan 31 23:27:25 EST 2021]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@101952da

 

2021-01-31 23:27:31,096 ERROR o.s.b.f.s.DefaultSingletonBeanRegistry [main]: Destroy method on bean with name 'org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory' threw an exception

java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@64a896b0: startup date [Sun Jan 31 23:27:25 EST 2021]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@101952da

 

2021-01-31 23:27:31,126 ERROR o.s.b.SpringApplication [main]: Application startup failed

服务一启动就报上面这种bootstrap启动错误,这个应该跟数据库、redis什么的没关系啊,最大可能是包依赖问题。但是研发提供的包没问题啊,已经有安装成功的先例了。我拿我的安装介质对比了安装完成的示例,最后确定除了配置文件不一样,安装介质都是一样的。而且我这还是docker安装啊。

经过众多无效尝试后,我今天试了一下直接在Linux系统中修改jar包配置文件的方法,启动测试一下,发现报错日志终于变了。原来问题出在这啊!毕竟是jar包,跟zip包什么的可能还是不一样的,不能直接在windows系统下直接拖拽文件。当然用jar命令打包估计也是可以的,修改配置文件然后用jar命令重新打包,但我没用这种方法。我用的是vim命令直接修改jar包里面的配置文件。

使用vim命令直接修改jar包里面的配置文件要先安装vim、zip和unzip,要不然Linux不支持这些命令。直接vim xxx.jar,然后用上下方向键移动光标来定位要修改的配置文件,当然也可以用右斜杠查找命令定位要修改的配置文件。定位要修改的配置文件后,按回车键就进入文件修改界面了。其他命令都跟vim编辑器一样。