Web 服务中的错误 org.springframework.boot.SpringApplication - 应用程序 运行 失败

ERROR in web service org.springframework.boot.SpringApplication - Application run failed

我在 Java 中有项目(网络服务)要维护。构建该项目的开发人员告诉我,他们使用了 Java 11 和 Gradle。所以我安装了:

  1. OpenJDK 服务器 VM Corretto-11.0.11.9.1(构建 11.0.11+9-LTS,混合模式,模拟客户端)
  2. Gradle 7.0.2
  3. 日食 IDE 2021-06 (4.20.0)

于 Windows 10。 在 Eclipse 中配置代理服务器并下载所有更新后结果与更新前相同,10785 错误,其中一些是:

ActiveProfiles cannot be resolved to a type
ActiveProfilesResolver cannot be resolved to a type
After cannot be resolved to a type
ApplicationPidFileWriter cannot be resolved to a type
Autowired cannot be resolved to a type

然后我安装了 Spring Tool Suite 4 4​​.11.0.RELEASE 并得到了同样的一组错误。 IntelliJ IDEA 2021.1.2(社区版)Build #IC-211.7442.40. 我运气更好 我设法构建了项目和 jar 文件,然后我在测试服务器上复制了 jar 文件(CentOS Linux 版本 7.5.1804OpenJDK 64 位服务器 VM AdoptOpenJDK构建 11.0.7+10,混合模式) 运行 jar 文件,结果是错误的:

08:39:14.532 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:/opt/rim/rim-server-1.0.jar!/com/rim/server/ex/TestingException.class]; nested exception is org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: URL [jar:file:/opt/rim/rim-server-1.0.jar!/com/rim/server/ex/TestingException.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 59
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:454)
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:316)
    at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:275)
    at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:132)
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:287)
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:242)
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:199)
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:315)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:691)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:528)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
    at com.<omited_private_data>.server.RimServerRoot.runSpring(RimServerRoot.java:28)
    at com.<omited_private_data>.server.RimServerRoot.main(RimServerRoot.java:22)
Caused by: org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: URL [jar:file:/opt/rim/rim-server-1.0.jar!/com/rim/server/ex/TestingException.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 59
    at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:57)
    at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103)
    at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:123)
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:430)
    ... 18 common frames omitted
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 59
    at org.springframework.asm.ClassReader.<init>(ClassReader.java:184)
    at org.springframework.asm.ClassReader.<init>(ClassReader.java:166)
    at org.springframework.asm.ClassReader.<init>(ClassReader.java:152)
    at org.springframework.asm.ClassReader.<init>(ClassReader.java:273)
    at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:54)
    ... 21 common frames omitted

我什至尝试过 Apache NetBeans IDE 12.0 在 NetBeans 中构建项目的结果是:

> Task :compileJava NO-SOURCE
> Task :processResources NO-SOURCE
> Task :classes UP-TO-DATE
> Task :jar UP-TO-DATE
> Task :assemble UP-TO-DATE
> Task :build
> Task :common:rina-commons:compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':common:rina-commons:compileJava'.
> Could not target platform: 'Java SE 11' using tool chain: 'JDK 8 (1.8)'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 8s

你的服务器 运行 所在的 java 版本应该与你的 jar 构建时使用的版本相同。您的错误消息“Unsupported class file major version 59”通常对我来说确实是这样。有很多与此相关的主题:

java.lang.IllegalArgumentException: Unsupported class file major version 59

...

我在 IntelliJ IDEA 中打开了项目点击了 Gradle 侧边栏:

右击构建; 选择“修改 运行 配置...”在参数字段的配置选项卡上输入 -x test;单击确定。双击将生成 jar 文件的构建。