我正在STS上开发一个spring 1.4.2应用程序,部署在weblogic 10 (j2ee 5,j-se 6)上,当我试图将应用程序作为Spring应用程序运行时,我会得到以下错误:
java.lang.UnsupportedClassVersionError: javax/annotation/ManagedBean : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.6.0_45]
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) ~[na:1.6.0_45]
at java.lang.ClassLoader.defineClass(ClassLoader.java:615) ~[na:1.6.0_45]
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) ~[na:1.6.0_45]
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) ~[na:1.6.0_45]
at java.net.URLClassLoader.access$000(URLClassLoader.java:58) ~[na:1.6.0_45]
at java.net.URLClassLoader$1.run(URLClassLoader.java:197) ~[na:1.6.0_45]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.6.0_45]
at java.net.URLClassLoader.findClass(URLClassLoader.java:190) ~[na:1.6.0_45]
at java.lang.ClassLoader.loadClass(ClassLoader.java:306) ~[na:1.6.0_45]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) ~[na:1.6.0_45]
at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ~[na:1.6.0_45]
at org.springframework.util.ClassUtils.forName(ClassUtils.java:250) ~[spring-core-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.registerDefaultFilters(ClassPathScanningCandidateComponentProvider.java:243) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.<init>(ClassPathScanningCandidateComponentProvider.java:116) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.<init>(ClassPathBeanDefinitionScanner.java:136) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.<init>(ClassPathBeanDefinitionScanner.java:111) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.<init>(ClassPathBeanDefinitionScanner.java:83) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext.<init>(AnnotationConfigEmbeddedWebApplicationContext.java:67) ~[spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.6.0_45]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) ~[na:1.6.0_45]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) ~[na:1.6.0_45]
at java.lang.reflect.Constructor.newInstance(Constructor.java:513) ~[na:1.6.0_45]
at java.lang.Class.newInstance0(Class.java:357) ~[na:1.6.0_45]
at java.lang.Class.newInstance(Class.java:310) ~[na:1.6.0_45]
at org.springframework.beans.BeanUtils.instantiate(BeanUtils.java:77) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.boot.SpringApplication.createApplicationContext(SpringApplication.java:597) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
at com.ejada.staripo.OnlineChannelBackendApplication.main(OnlineChannelBackendApplication.java:22) [main/:na]我知道错误的原因(编译时的旧版本,运行时的新版本).我无法弄清楚是什么导致了...I应该用java 6编译我的应用程序.但是错误说一些东西是用java 7编译的。
等级公会档案:
buildscript {
ext {
springBootVersion = '1.4.2.RELEASE'
}
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
group = 'com.mypack'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.6 //java6
repositories {
mavenCentral()
mavenLocal()
}
configurations {
providedRuntime
//jaxb
}
// tag::wsdl[]
// task genJaxb {
// ext.sourcesDir = "${projectDir}/src/main/java"
// ext.classesDir = "${buildDir}/classes/jaxb"
// ext.schema1 = "src/main/resources/com/ejada/staripo/wsdl/ELMCitizenInfoInq.wsdl"
// ext.src1 = "${projectDir}/src/main/java/com/ejada/staripo/backend/elm/citizeninfo"
// ext.schema2 = "src/main/resources/com/ejada/staripo/wsdl/ELMMuqeemInfoInq.wsdl"
// ext.src2 = "${projectDir}/src/main/java/com/ejada/staripo/backend/elm/muqeeminfo"
//
// outputs.dir classesDir
//
// doLast() {
// project.ant {
// taskdef name: "xjc", classname: "com.sun.tools.xjc.XJCTask",
// classpath: configurations.jaxb.asPath
// mkdir(dir: sourcesDir)
// mkdir(dir: classesDir)
//
// xjc(destdir: sourcesDir, schema: schema1,
// package: "com.ejada.staripo.backend.elm.citizeninfo") {
// arg(value: "-wsdl")
// produces(dir: sourcesDir, includes: "**/*.java")
// }
//
// xjc(destdir: sourcesDir, schema: schema2,
// package: "com.ejada.staripo.backend.elm.muqeeminfo") {
// arg(value: "-wsdl")
// produces(dir: sourcesDir, includes: "**/*.java")
// }
//
//
// javac(destdir: classesDir, source: 1.8, target: 1.8, debug: true,
// debugLevel: "lines,vars,source",
// classpath: configurations.jaxb.asPath) {
// src(path: src1)
// include(name: "**/*.java")
// include(name: "*.java")
// }
//
// copy(todir: classesDir) {
// fileset(dir: src1, erroronmissingdir: false) {
// exclude(name: "**/*.java")
// }
// }
//
// javac(destdir: classesDir, source: 1.8, target: 1.8, debug: true,
// debugLevel: "lines,vars,source",
// classpath: configurations.jaxb.asPath) {
// src(path: src2)
// include(name: "**/*.java")
// include(name: "*.java")
// }
//
// copy(todir: classesDir) {
// fileset(dir: src2, erroronmissingdir: false) {
// exclude(name: "**/*.java")
// }
// }
// }
// }
// }
// end::wsdl[]
dependencies {
compile('org.springframework.boot:spring-boot-legacy:1.1.0.RELEASE')
compile('org.springframework.boot:spring-boot-starter-web:1.4.2.RELEASE')
compile('com.fasterxml.jackson.core:jackson-databind:2.6.7') //java6
compile('org.springframework.ws:spring-ws-core')
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.2.0')
compile('org.projectlombok:lombok:1.16.10')
compile('com.oracle:ojdbc6:11.1.0.7.0') //java6
//compileOnly('org.springframework.boot:spring-boot-devtools')
compileOnly('javax.servlet:servlet-api:2.5')
//compile(files(genJaxb.classesDir).builtBy(genJaxb))
//jaxb "com.sun.xml.bind:jaxb-xjc:2.1.7"
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat') // commented for java6
providedRuntime('org.apache.tomcat:tomcat-juli:7.0.59') // java6
//compileOnly group:'org.apache.tomcat', name:'tomcat-juli', version:'7.0.59' // java6
testCompile('org.springframework.boot:spring-boot-starter-test')
//testCompile('org.springframework.security:spring-security-test')
}
/*compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.session:spring-session-core')
*/
//bootJar { //commented 4 java6
// baseName = 'gs-consuming-web-service'
//version = '0.1.0'
// from genJaxb.classesDir
//}
//task afterEclipseImport {
// dependsOn genJaxb
//}下面是生成的war中的lib文件夹:

发布于 2018-04-23 14:41:37
我所做的是,我制造了一场战争,并将它部署到外部的that 7,而不是嵌入的.因为一些我不知道的原因,那里的错误更明显了.它直接指向导致错误的包,它位于spring core中,因此我需要使用2.2.4版本的package
发布于 2018-04-24 03:49:47
您需要在为Java 6构建脚本中将tomcat版本设置为7。您可以在Spring文档中找到一些额外的配置。https://docs.spring.io/spring-boot/docs/1.4.4.RELEASE/reference/htmlsingle/#howto-use-java-6
例如: Gradle脚本
ext['tomcat.version'] = '7.0.59'我希望这能帮上忙。
发布于 2018-04-22 16:01:42
首先,sourceCompatibility只指定代码的源代码兼容性。要生成所需版本的.class文件,应该使用targetCompatibility。见this answer。
第二,您的错误的原因:
java.lang.UnsupportedClassVersionError: javax/批注/ManagedBean:不支持的major.minor版本51.0
不是:
编译时旧版本,运行时新版本
但是:编译时的新版本,的旧版本
第三,javax.annotation.ManagedBean不是从您的源代码编译的,而是Javax注释API的一部分,您应该选择一个与java-6兼容的jar。
https://stackoverflow.com/questions/49967597
复制相似问题