从Spring引导2.4.13升级到2.7.4之后,我在容器化的Scala应用程序上开始面临这个错误(我使用的是Scala 2.12(
java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories nor in META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports. If you are using a custom packaging, make sure that file is correct.
at org.springframework.util.Assert.notEmpty(Assert.java:470)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getCandidateConfigurations(AutoConfigurationImportSelector.java:185)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getAutoConfigurationEntry(AutoConfigurationImportSelector.java:125)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector$AutoConfigurationGroup.process(AutoConfigurationImportSelector.java:440)
at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGrouping.getImports(ConfigurationClassParser.java:879)
at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:809)
at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorHandler.process(ConfigurationClassParser.java:780)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:192)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:247)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:311)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:112)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:746)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
at com.eb.data.batch.writer.TermSuccessBatchMainClass$.main(TermSuccessBatch.scala:61)
at com.eb.data.batch.writer.TermSuccessBatchMainClass.main(TermSuccessBatch.scala)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.spark.deploy.JavaMainApplication.start(SparkApplication.scala:52)
at org.apache.spark.deploy.SparkSubmit.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:958)
at org.apache.spark.deploy.SparkSubmit.doRunMain$1(SparkSubmit.scala:180)
at org.apache.spark.deploy.SparkSubmit.submit(SparkSubmit.scala:203)
at org.apache.spark.deploy.SparkSubmit.doSubmit(SparkSubmit.scala:90)
at org.apache.spark.deploy.SparkSubmit$$anon$2.doSubmit(SparkSubmit.scala:1046)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:1055)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
在做了一些研究之后,我找到了可能的解决方案,比如在plugins.sbt
文件中包含以下插件之一:
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.2")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.9.11")
addSbtPlugin("org.springframework.boot" % "spring-boot-maven-plugin" % "2.7.4")
然而,我无法解决这些插件中的最后2个,但该文件包含其他插件,这些插件在我丢弃了一个存储库配置问题后得到了正确解决。事实上,第一个问题可以解决,但并没有解决问题。我还将这一行附加到build.sbt
:
enablePlugins(JavaAppPackaging)
[error] (update) sbt.librarymanagement.ResolveException: Error downloading com.typesafe.sbt:sbt-native-packager;sbtVersion=1.0;scalaVersion=2.12:1.9.11
[error] Not found
[error] Not found
[error] not found: https://repo1.maven.org/maven2/com/typesafe/sbt/sbt-native-packager_2.12_1.0/1.9.11/sbt-native-packager-1.9.11.pom
[error] not found: /Users/myuser/.ivy2/localcom.typesafe.sbt/sbt-native-packager/scala_2.12/sbt_1.0/1.9.11/ivys/ivy.xml
[error] unauthorized: https://my-nexus-server/repository/ivy-releases-group/com.typesafe.sbt/sbt-native-packager/scala_2.12/sbt_1.0/1.9.11/ivys/artifact.xml (Sonatype Nexus Repository Manager)
[error] unauthorized: https://my-nexus-server/repository/public/com/typesafe/sbt/sbt-native-packager_2.12_1.0/1.9.11/sbt-native-packager-1.9.11.pom (Sonatype Nexus Repository Manager)
[error] not found: https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.typesafe.sbt/sbt-native-packager/scala_2.12/sbt_1.0/1.9.11/ivys/ivy.xml
[error] not found: https://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.sbt/sbt-native-packager/scala_2.12/sbt_1.0/1.9.11/ivys/ivy.xml
最后两个在我的nexus存储库上引发了一个未经授权的错误,但.sbt凭据设置正确,它能够通过nexus服务器解决其他插件的任何依赖关系(我猜它是一个未找到的插件(。
还试图修改的合并策略
lazy val assemblySettings = Seq(
assembly / assemblyMergeStrategy := {
case PathList("META-INF", "spring.factories") => MergeStrategy.filterDistinctLines
case PathList("META-INF", xs @ _*) => MergeStrategy.discard
case _ => MergeStrategy.first
}
)
至
lazy val assemblySettings = Seq(
assembly / assemblyMergeStrategy := {
case PathList("META-INF", "spring.factories") => MergeStrategy.filterDistinctLines
case PathList("META-INF", "spring") => MergeStrategy.filterDistinctLines
case PathList("META-INF", xs @ _*) => MergeStrategy.discard
case _ => MergeStrategy.first
}
)
由于自动配置似乎已经在spring-boot 2.7上移动,并且错误消息说它试图在META-INF/spring
下定位它,因此不起作用
面对这个问题有什么想法吗?
由于弹簧自动配置设置已在弹簧2.7上从META-INF/spring.factories
移动到META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
,在sbt构建的合并策略上替换此路径成功:
assembly / assemblyMergeStrategy := {
case PathList("META-INF", "spring.factories") => MergeStrategy.filterDistinctLines // Not sure if something in this path is needed anymore
case PathList("META-INF", "spring", "org.springframework.boot.autoconfigure.AutoConfiguration.imports") => MergeStrategy.filterDistinctLines
case PathList("META-INF", xs @ _*) => MergeStrategy.discard
case _ => MergeStrategy.first
}