【问题标题】:ERROR in web service org.springframework.boot.SpringApplication - Application run failedWeb 服务 org.springframework.boot.SpringApplication 中的错误 - 应用程序运行失败
【发布时间】:2021-09-11 10:12:18
【问题描述】:

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

  1. OpenJDK 服务器 VM Corretto-11.0.11.9.1(内部版本 11.0.11+9-LTS,混合模式,模拟客户端)
  2. Gradle 7.0.2
  3. Eclipse 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 (Community Edition) Build #IC-211.7442.40 让我更加幸运。 我设法构建项目和 jar 文件,然后我在测试服务器上复制了 jar 文件(CentOS Linux 版本 7.5.1804OpenJDK 64 位服务器 VM AdoptOpenJDK build 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

【问题讨论】:

  • 您使用的是不支持 java11 的 Spring Boot 版本。所以要么升级库(Spring Boot 和朋友),要么降级 JDK。

标签: java spring-boot web-services gradle


【解决方案1】:

运行服务器的 java 版本应该与构建 jar 的版本相同。您的错误消息“不支持的类文件主要版本 59”通常对我来说确实表明了这一点。有很多关于这个的线程:

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

android launch issues. Unsupported class file major version 57

...

【讨论】:

  • 现在我在 Eclipse 中有同样的错误,但在 IntelliJ IDEA ERROR o.s.boot.SpringApplication - 应用程序运行失败 java.lang.IllegalArgumentException:在 META-INF/spring.factories 中找不到自动配置类。如果您使用的是自定义包装,请确保该文件正确无误。
  • 你是否在你的 gradle 中正确包含了 spring-boot-plugin ?你还必须配置你的主类: ${start-class} ...见stackoverflow.com/questions/38792031/…
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 2020-12-18
    • 1970-01-01
    • 2021-09-26
    • 1970-01-01
    • 1970-01-01
    • 2015-06-09
    • 2023-04-05
    • 2022-01-05
    • 2022-12-04
    相关资源
    最近更新 更多