如何解决MacOS IDEA编译的jar包在Linux环境出现循环依赖错误?

macos系统(m2max下图所示)
image.png
在idea(2024.2专业版和教育版都试过)上本地编译代码通过(本地直接使用编译好的jar包 使用命令启动:java -jar --debug 命令启动报错循环依赖);
但是使用编译后的jar包发布线上后,启动后报错循环依赖,同样环境和项目win10上编译后正常发布线上并启动。。。。。
如下图所示:

9:43:13.830 [main] DEBUG c.b.mybatisplus.MybatisConfiguration - addMappedStatement: com.shiny.sf.projectcheck.mapper.ItemCheckInfoMapper.selectMapsPage
09:43:13.830 [main] DEBUG c.b.mybatisplus.MybatisConfiguration - addMappedStatement: com.shiny.sf.projectcheck.mapper.ItemCheckInfoMapper.selectObjs
09:43:13.865 [main] WARN  o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'investmentOfFundsBizService': Unsatisfied dependency expressed through field 'budgetExecuteBizService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'budgetExecuteBizService' defined in URL [jar:file:/Users/xuquanke/CareerPlanning/Internet/projects/shiny/shiny-sf/target/shiny-sf.jar!/BOOT-INF/classes!/com/shiny/sf/bigScreen/tl/biz/impl/BudgetExecuteBizServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'TLBigScreenServiceImpl': Unsatisfied dependency expressed through field 'agreementService'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'agreementServiceImpl': Bean with name 'agreementServiceImpl' has been injected into other beans [auditBusinessServiceImpl] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesForType' with the 'allowEagerInit' flag turned off, for example.
09:43:13.866 [main] INFO  c.alibaba.druid.pool.DruidDataSource - {dataSource-1} closing ...
09:43:13.869 [main] INFO  c.alibaba.druid.pool.DruidDataSource - {dataSource-1} closed
09:43:13.881 [main] INFO  o.a.catalina.core.StandardService - Stopping service [Tomcat]
09:43:13.888 [main] INFO  o.s.b.a.l.ConditionEvaluationReportLoggingListener - 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
09:43:13.910 [main] ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'investmentOfFundsBizService': Unsatisfied dependency expressed through field 'budgetExecuteBizService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'budgetExecuteBizService' defined in URL [jar:file:/Users/xuquanke/CareerPlanning/Internet/projects/shiny/shiny-sf/target/shiny-sf.jar!/BOOT-INF/classes!/com/shiny/sf/bigScreen/tl/biz/impl/BudgetExecuteBizServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'TLBigScreenServiceImpl': Unsatisfied dependency expressed through field 'agreementService'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'agreementServiceImpl': Bean with name 'agreementServiceImpl' has been injected into other beans [auditBusinessServiceImpl] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesForType' with the 'allowEagerInit' flag turned off, for example.
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:660)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:920)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)
    at com.shiny.sf.ShinySfApplication.main(ShinySfApplication.java:16)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'budgetExecuteBizService' defined in URL [jar:file:/Users/xuquanke/CareerPlanning/Internet/projects/shiny/shiny-sf/target/shiny-sf.jar!/BOOT-INF/classes!/com/shiny/sf/bigScreen/tl/biz/impl/BudgetExecuteBizServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'TLBigScreenServiceImpl': Unsatisfied dependency expressed through field 'agreementService'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'agreementServiceImpl': Bean with name 'agreementServiceImpl' has been injected into other beans [auditBusinessServiceImpl] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesForType' with the 'allowEagerInit' flag turned off, for example.
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:229)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1372)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1222)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:657)
    ... 28 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'TLBigScreenServiceImpl': Unsatisfied dependency expressed through field 'agreementService'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'agreementServiceImpl': Bean with name 'agreementServiceImpl' has been injected into other beans [auditBusinessServiceImpl] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesForType' with the 'allowEagerInit' flag turned off, for example.
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:660)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887)
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791)
    ... 41 common frames omitted
Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'agreementServiceImpl': Bean with name 'agreementServiceImpl' has been injected into other beans [auditBusinessServiceImpl] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesForType' with the 'allowEagerInit' flag turned off, for example.
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:649)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:657)
    ... 56 common frames omitted

排查问题:
(1)排查了maven(使用3.9.2)和jdk(1.8)并没有发现什么问题
(2)尝试过mvn clean 后 mvn install和清除idea自带的缓存,无效
(3)怀疑是macos系统或者idea的mac版本自带的问题

解决方案:
(1)看网上说是mac打包后的jar包解压后在重新打包一下就可以,然而我试了并不行;(🔗:https://blog.csdn.net/weixin_39570655/article/details/129222407
(2)还有说是加@lazy懒加载,结果是也不行....(🔗:https://www.seasidecrab.com/Java/1166.html
(3)还有说和springboot的版本有关系,mac在3.5之后就不允许这种循环依赖问题,也不确定是不是这样。。。(🔗:https://www.seasidecrab.com/Java/1166.html
希望能解决下macos在idea打包问题,各位大神有遇到这种问题吗??

阅读 923
avatarAI BotBETA

针对您描述的问题,即在MacOS上使用IDEA编译的Jar包在Linux环境下运行时出现循环依赖错误,而相同代码在Windows环境下编译则没有问题,这里有几个可能的解决方向和检查点:

1. 检查构建配置

首先确保在MacOS上的Maven构建配置(如pom.xml)与Windows上完全一致。特别是检查任何可能影响类加载顺序或打包方式的插件配置,如Spring Boot Maven Plugin的layout属性。

2. 验证Jar包内容

  • 比较Jar包:在MacOS和Windows上分别构建Jar包,并比较它们的内容是否完全一致。可以使用jar tvf your-jar-file.jar命令来列出Jar包内容。
  • 检查Manifest文件:检查Manifest文件中的Class-PathMain-Class是否正确,确保没有路径差异导致的问题。

3. 考虑JDK和Maven版本差异

  • JDK版本:虽然您提到JDK版本相同(1.8),但确保在MacOS和Linux上的JDK补丁级别也相同。
  • Maven版本:虽然您使用的是Maven 3.9.2,但也可以尝试更新到更高版本(如Maven 3.8.x,注意选择稳定的版本)来看是否解决问题。

4. 检查Spring Boot版本和配置

  • Spring Boot版本:您提到可能与Spring Boot版本有关。请检查您的Spring Boot版本是否支持您的JDK版本,并且没有已知的与循环依赖相关的问题。
  • 配置Spring Boot以处理循环依赖:通常Spring Boot可以很好地处理循环依赖,但如果有特定配置(如Bean的创建顺序)导致问题,可能需要调整。尝试在Spring Boot配置中启用更详细的日志记录,以查看是否有关于Bean创建的警告或错误。

5. 使用Docker或类似容器技术

  • 构建容器镜像:为了排除操作系统差异,可以尝试将您的应用打包成Docker容器。在Dockerfile中指定与Linux环境相匹配的JDK版本和Maven配置,确保构建过程完全可控且一致。

6. 清理和重建

  • 完全清理:在MacOS上,除了使用mvn clean外,还可以尝试删除~/.m2/repository下的相关依赖缓存,以确保没有旧的或损坏的依赖项影响构建。

7. 咨询和社区帮助

  • 查看Spring Boot和Maven的官方文档及社区:看看是否有其他开发者遇到并解决了类似的问题。
  • 在Stack Overflow提问:如果上述步骤都无法解决问题,您可以在Stack Overflow上详细描述您的问题,包括环境配置、错误日志和已经尝试的解决方案,以便社区成员提供帮助。

希望这些建议能帮助您解决问题!

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏