英文:
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 61 at org.springframework.asm.ClassReader.<init>ClassReader.java
问题
以下是您提供的代码的翻译部分:
我有一个应用程序,已迁移到Spring Boot 3.1.0和Java 17。现在我正在尝试将其与Spring 6.0.9一起使用(在此之前,正如您在注释的依赖项中所看到的那样,它明确降级了Spring版本,因为版本升级的历史记录。
因此,当我尝试运行bootRun配置时,
buildscript {
ext {
springBootVersion = '3.1.0';
}
repositories {
maven {
url "https://nexus.dev.domoy.ru/repository/mvn-remote/";
}
maven {
url "https://nexus.dev.domoy.ru/repository/gradle-remote-plugins/";
}
maven {
credentials {
username "$mavenUser"
password "$mavenPassword"
}
url "$mavenUrl"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7.1"
classpath "gradle.plugin.com.github.viswaramamoorthy:gradle-util-plugins:0.1.0-RELEASE"
}
}
...
我遇到了以下问题,尽管应用程序使用的是17版本的Java,gradle也是在17版本的Java上运行的,但似乎没有东西需要使用上述Java版本?
2023-06-12 18:36:20.466 [main] WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - 在上下文初始化期间遇到异常 - 取消刷新尝试: org.springframework.beans.factory.BeanDefinitionStoreException: 无法读取候选组件类: 文件 [D:\Java\domrf2\build\classes\java\main\rf\dom\billing\ap\Application.class];嵌套异常是 org.springframework.core.NestedIOException: ASM ClassReader 无法解析类文件 - 可能是由于不支持的新Java类文件版本: 文件 [D:\Java\domrf2\build\classes\java\main\rf\dom\billing\ap\Application.class];嵌套异常是 java.lang.IllegalArgumentException: 不支持的类文件主版本 61
2023-06-12 18:36:20.475 [main] ERROR o.s.boot.SpringApplication - 应用程序运行失败
org.springframework.beans.factory.BeanDefinitionStoreException: 无法读取候选组件类: 文件 [D:\Java\domrf2\build\classes\java\main\rf\dom\billing\ap\Application.class];嵌套异常是 org.springframework.core.NestedIOException: ASM ClassReader 无法解析类文件 - 可能是由于不支持的新Java类文件版本: 文件 [D:\Java\domrf2\build\classes\java\main\rf\dom\billing\ap\Application.class];嵌套异常是 java.lang.IllegalArgumentException: 不支持的类文件主版本 61
...
希望这对您有所帮助。如果您有任何其他疑问,请随时提出。
英文:
I have an app that was migrated to Spring Boot 3.1.0 and Java 17. Now I'm trying to make it working together with Spring 6.0.9 (before that, as you may see in the commented dependencies, it had explicitly downgraded Spring version because o history of the versions upgrade.
So, when I try to run bootRun
fo rth econfiguration,
buildscript {
ext {
springBootVersion = '3.1.0'
}
repositories {
maven {
url "https://nexus.dev.domoy.ru/repository/mvn-remote/"
}
maven {
url "https://nexus.dev.domoy.ru/repository/gradle-remote-plugins/"
}
maven {
credentials {
username "$mavenUser"
password "$mavenPassword"
}
url "$mavenUrl"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7.1"
classpath "gradle.plugin.com.github.viswaramamoorthy:gradle-util-plugins:0.1.0-RELEASE"
}
}
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.sonarqube'
apply plugin: 'jacoco'
apply plugin: 'com.github.ManifestClasspath'
group = 'rf.dom.billing'
archivesBaseName = 'billing-ap'
version = '1.0.5'
mainClassName = 'rf.dom.billing.ap.Application'
sourceCompatibility = 1.17
targetCompatibility = 1.17
repositories {
maven {
url "https://nexus.dev.domoy.ru/repository/mvn-remote/"
}
maven {
url "https://nexus.dev.domoy.ru/repository/gradle-remote-plugins/"
}
maven {
credentials {
username "$mavenUser"
password "$mavenPassword"
}
url "$mavenUrl"
}
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-starter-parent:Hoxton.SR10"
}
}
//sonarqube {
// properties {
// property "sonar.host.url", "https://sonarqube.domoy.ru/sonarqube"
// property "sonar.login", "83f2b4d2c20b87a6f96385bb947d3531dbd4ba8e"
// property "sonar.projectKey", "billing-ap"
// property "sonar.projectName", "BILLING-ap"
// property "sonar.exclusions", "**/dto/**/*.java"
// }
//}
jacoco {
toolVersion = "0.8.8"
}
bootRun {
systemProperties System.properties
systemProperties.remove("java.endorsed.dirs")
}
sourceSets {
main {
java {
srcDirs = ['src/main/java', 'src/generated/java']
}
}
}
configurations {
bouncyCastle
runtime.exclude group: "org.springframework.boot", module: "spring-boot-starter-tomcat"
compile.exclude group: "net.sf.ehcache"
all {
resolutionStrategy {
// Force jackson 2.4.4 for Spark
force 'com.fasterxml.jackson.core:jackson-core:2.13.5', 'com.fasterxml.jackson.core:jackson-databind:2.13.5', 'com.fasterxml.jackson.core:jackson-annotations:2.13.5'
}
}
}
task copyCoreJarsToLibs(type: Copy, dependsOn: jar) {
from "build/libs"
into "${rootDir}/artifacts/docker/billing_ap"
exclude '*.original', '*replicator*'
}
task copyDockerfiles(type: Copy) {
from "${rootDir}/dockerfile"
into "${rootDir}/artifacts/docker/billing_ap"
}
task copyDockerfilesProd(type: Copy) {
from "${rootDir}/dockerfile/Dockerfile-prod"
into "${rootDir}/artifacts/docker/billing_ap"
rename { String fileName ->
fileName.replace("Dockerfile-prod",
"Dockerfile")
}
}
task collectArtifacts {
dependsOn(build, copyCoreJarsToLibs, copyDockerfiles)
}
task collectArtifactsProd {
dependsOn(build, copyCoreJarsToLibs, copyDockerfilesProd)
}
ext['elasticsearch.version'] = '7.2.0'
dependencies {
implementation 'javax.validation:validation-api:2.0.1.Final'
implementation "org.springframework.boot:spring-boot-starter:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-web:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-webflux:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-data-rest:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-mail:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-oauth2-client:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-oauth2-resource-server:${springBootVersion}"
implementation("org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}") {
// exclude group: 'org.hibernate', module: 'hibernate-entitymanager'
}
implementation "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}"
//implementation "org.springframework.boot:spring-boot-actuator-autoconfigure:${springBootVersion}"
//implementation "org.springframework.boot:spring-boot-autoconfigure:${springBootVersion}"
runtime 'io.micrometer:micrometer-registry-prometheus'
// implementation 'org.springframework.amqp:spring-amqp:2.3.11'
// implementation 'org.springframework.boot:spring-boot-starter-undertow'
// implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
// implementation 'org.springframework.security:spring-security-oauth2-jose:5.5.7'
// implementation 'org.springframework.security:spring-security-oauth2-core:5.5.7'
// implementation 'org.springframework.security:spring-security-core:5.5.7'
// implementation 'org.springframework.security:spring-security-web:5.5.7'
// implementation 'org.springframework.security:spring-security-oauth2-client:5.7.5'
// implementation 'org.springframework.security:spring-security-oauth2-resource-server:5.5.7'
// implementation 'org.springframework:spring-core:6.0.9'
// implementation 'org.springframework:spring-beans:6.0.9'
// implementation 'org.springframework:spring-expression:6.0.9'
// implementation 'org.springframework:spring-webflux:6.0.9'
// implementation 'org.springframework:spring-webmvc:6.0.9'
// implementation 'org.springframework:spring-web:6.0.9'
implementation 'io.projectreactor:reactor-core:3.2.12.RELEASE'
compileOnly 'org.projectlombok:lombok:1.18.22+'
annotationProcessor 'org.projectlombok:lombok:1.18.22+'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22+'
annotationProcessor 'org.hibernate:hibernate-jpamodelgen:5.4.4.Final'
implementation 'org.postgresql:postgresql:42.2.8'
implementation 'com.zaxxer:HikariCP:3.4.0'
//implementation 'org.flywaydb:flyway-core:5.2.4'
implementation 'org.hibernate.javax.persistence:hibernate-jpa-2.2-api:1.0.0.Beta2'
implementation 'net.bull.javamelody:javamelody-spring-boot-starter:1.79.0'
implementation 'commons-io:commons-io:2.6'
implementation 'io.springfox:springfox-swagger2:3.0.0'
//
// {
// exclude module: 'swagger-annotations'
// exclude module: 'swagger-models'
// }
//implementation 'io.swagger:swagger-annotations:1.5.23'
//implementation 'io.swagger:swagger-models:1.5.23'
implementation 'io.springfox:springfox-swagger-ui:3.0.0'
implementation 'rf.dom.billing:billing-model:RELEASE.2.2.49'
implementation ('rf.dom.billing:billing-common:RELEASE.1.0.6')
{
exclude group: 'bouncycastle', module: 'bcprov-jdk14'
}
implementation 'rf.dom.billing:billing-tracking:RELEASE.1.1.13'
implementation 'rf.dom.billing:billing-docstore-integration:1.0.3'
/*Cloud start*/
implementation 'org.springframework.cloud:spring-cloud-starter-config:2.1+'
implementation 'org.springframework.cloud:spring-cloud-starter:2.1+'
implementation 'org.springframework.cloud:spring-cloud-config-client:2.1+'
/*Cloud end*/
implementation 'org.jxls:jxls-poi:1.2.0'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.boot:spring-boot-starter-undertow'
testImplementation 'org.testng:testng:6.14.3'
testImplementation 'org.powermock:powermock-api-mockito2:2.0.2'
testImplementation 'com.opentable.components:otj-pg-embedded:0.13.1'
testImplementation 'org.flywaydb:flyway-core:5.2.4'
//trivy
// implementation 'ch.qos.logback:logback-core:1.2.9'
// implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.5'
// implementation 'com.fasterxml.jackson.core:jackson-core:2.13.5'
// implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.5'
// implementation 'com.google.guava:guava:30.0-jre'
// //implementation 'com.nimbusds:nimbus-jose-jwt:7.9'
// implementation 'com.nimbusds:nimbus-jose-jwt:8.21'
// implementation 'com.nimbusds:oauth2-oidc-sdk:9.19'
// implementation 'commons-io:commons-io:2.7'
//
// implementation 'io.netty:netty-codec:4.1.77.Final'
// implementation 'io.netty:netty-codec-http:4.1.77.Final'
// implementation 'io.netty:netty-codec-http2:4.1.77.Final'
// implementation 'io.netty:netty-codec-socks:4.1.77.Final'
// implementation 'io.netty:netty-handler:4.1.77.Final'
////
// implementation 'io.undertow:undertow-core:2.2.19.Final'
// implementation 'net.minidev:json-smart:2.4.9'
// implementation 'org.apache.commons:commons-compress:1.21'
// implementation 'org.apache.httpcomponents:httpclient:4.5.13'
// implementation 'org.apache.poi:poi:5.2.1'
// implementation 'org.apache.poi:poi-ooxml:5.2.1'
// implementation 'org.bouncycastle:bcprov-jdk14:1.73'
// //implementation 'bouncycastle:bcprov-jdk14:161'
// //implementation 'bouncycastle:bcprov-jdk14:161'
// implementation 'org.bouncycastle:bcprov-jdk15on:1.67'
// implementation 'org.elasticsearch:elasticsearch:7.9.2'
// implementation 'org.elasticsearch.client:elasticsearch-rest-client:7.9.2'
// implementation 'org.elasticsearch.client:elasticsearch-rest-high-level-client:7.9.2'
// implementation 'org.eclipse.jetty:jetty-util:11.0.15'
//// implementation 'org.dom4j:dom4j:2.1.3'
// implementation 'org.eclipse.jetty:jetty-http:11.0.15'
// implementation 'org.eclipse.jetty:jetty-io:11.0.15'
// implementation 'org.hibernate.validator:hibernate-validator:6.0.20.Final'
// implementation 'org.postgresql:postgresql:42.5.1'
// implementation 'org.yaml:snakeyaml:1.33'
// implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.0'
// implementation 'org.apache.tomcat.embed:tomcat-embed-core:9.0.69'
bouncyCastle 'org.bouncycastle:bcprov-jdk14:1.73'
compileOnly 'jakarta.servlet:jakarta.servlet-api:6.0.0'
}
task installBouncyCastleJar {
doLast {
def bcFile = file('build/libs/bcprov-jdk14-1.73.jar')
def groupId = 'bouncycastle'
def artifactId = 'bcprov-jdk14'
def version = '173'
def packaging = 'jar'
// project.repositories.maven.install([
// file: bcFile,
// groupId: groupId,
// artifactId: artifactId,
// version: version,
// packaging: packaging
// ])
}
}
project.afterEvaluate {
build.dependsOn(installBouncyCastleJar)
}
tasks.withType(JavaCompile) {
options.annotationProcessorGeneratedSourcesDirectory = file("src/generated/java")
}
wrapper {
distributionType = Wrapper.DistributionType.ALL
gradleVersion = '6.0'
}
test {
// enable TestNG support (default is JUnit)
useTestNG()
testLogging.showStandardStreams = true
testLogging.exceptionFormat = 'full'
}
task printName {
doLast {
print project.name
}
}
task printVersion {
doLast {
print project.version
}
}
I'm getting the below problkem, while the app is on 17th kava, gradle is ran on 17th java and nothing may require the above Java version?
2023-06-12 18:36:20.466 [main] WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [D:\Java\domrf2\build\classes\java\main\rf\dom\billing\ap\Application.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: file [D:\Java\domrf2\build\classes\java\main\rf\dom\billing\ap\Application.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 61
2023-06-12 18:36:20.475 [main] ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [D:\Java\domrf2\build\classes\java\main\rf\dom\billing\ap\Application.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: file [D:\Java\domrf2\build\classes\java\main\rf\dom\billing\ap\Application.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 61
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:452)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:315)
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:276)
at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:132)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:296)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:250)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:207)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:175)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:319)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:280)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:96)
at
org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:707)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:533)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at rf.dom.billing.ap.Application.main(Application.java:24)
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: file [D:\Java\domrf2\build\classes\java\main\rf\dom\billing\ap\Application.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 61
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: file [D:\Java\domrf2\build\classes\java\main\rf\dom\billing\ap\Application.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 61
at org.springframework.core.type.classreading.SimpleMetadataReader.getClassReader(SimpleMetadataReader.java:60)
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:49)
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:429)
... 21 common frames omitted
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 61
at org.springframework.asm.ClassReader.<init>(ClassReader.java:196)
at org.springframework.asm.ClassReader.<init>(ClassReader.java:177)
at org.springframework.asm.ClassReader.<init>(ClassReader.java:163)
at org.springframework.asm.ClassReader.<init>(ClassReader.java:284)
at org.springframework.core.type.classreading.SimpleMetadataReader.getClassReader(SimpleMetadataReader.java:57)
... 25 common frames omitted
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 61
Execution failed for task ':bootRun'.
> Process 'command 'D:\Java\jdk-17.0.2\bin\java.exe'' finished with non-zero exit value 1
UPD after updating ASM to 9.5 still getting the problem:
答案1
得分: 1
你可能正在使用过旧版本的Java ASM。
根据版本列表,您至少需要版本9.1才能支持Java 17。
查看这个SO问题的答案,以找出哪个依赖项正在使用过时的ASM版本:使用Gradle查找依赖树
我还注意到您在引用Gradle版本6,这也可能是个问题。请尝试将其更新到更近期的版本,因为Gradle本身也在使用ASM。
Gradle兼容性图表显示您至少需要版本7.3才能支持Java 17。
英文:
You probably are using a too old version of Java ASM.
According to the versions list you need at least version 9.1 to support Java 17.
See answers to this SO question to find out which dependency is using the outdated ASM version: Using Gradle to find dependency tree
I also saw that you are referring to Gradle version 6, this could also be a problem. Please try to update it to a more recent version, since Gradle itself also is using ASM.
The Gradle compatibility chart shows that you need at least version 7.3 to support Java 17
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论