使用JDK 1.6时的Spring Boot JDBC异常

时间:2016-03-14 21:23:16

标签: java spring maven jdbc

我尝试使用JDK 1.6创建一个Spring Boot应用程序,当我添加" spring-boot-starter-jdbc"依赖我在下面得到了例外。我理解异常与编译器版本差异有关,但不确定如何解决问题。如果我删除" spring-boot-starter-jdbc"依赖一切都很好。解决此问题的任何帮助以及如何进一步排除故障都会有所帮助。

POM依赖关系:

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<tomcat.version>7.0.59</tomcat.version>
<java.version>1.6</java.version>
<main.basedir>${basedir}/../..</main.basedir>
<m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot>
<spring.starter.version>1.3.3.RELEASE</spring.starter.version>
<spring-boot.version>1.3.3.RELEASE</spring-boot.version>
<version.oracle>11.2.0.1.0</version.oracle>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.starter.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.starter.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>${spring.starter.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-legacy</artifactId>
<version>1.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>${spring.starter.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>${version.oracle}</version>
</dependency>
</dependencies>

例外:

3/14/16 16:37:04:412 EDT] 00000009 SystemOut     O 2016-03-14 16:37:04.412 ERROR 41116 --- [    Default : 0] o.s.boot.SpringApplication               : Application startup failed

java.lang.UnsupportedClassVersionError: JVMCFRE003 bad major version; class=org/apache/tomcat/jdbc/pool/DataSource, offset=6
at java.lang.ClassLoader.defineClassImpl(Native Method) ~[na:1.6.0]
at java.lang.ClassLoader.defineClass(ClassLoader.java:275) ~[na:1.6.0]
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:74) ~[na:na]
at com.ibm.ws.classloader.CompoundClassLoader._defineClass(CompoundClassLoader.java:775) ~[com.ibm.ws.runtime.jar:WAS70.SERV1 [cf291321.01]]
at com.ibm.ws.classloader.CompoundClassLoader.localFindClass(CompoundClassLoader.java:690) ~[com.ibm.ws.runtime.jar:WAS70.SERV1 [cf291321.01]]
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:513) ~[com.ibm.ws.runtime.jar:WAS70.SERV1 [cf291321.01]]
at java.lang.ClassLoader.loadClass(ClassLoader.java:626) ~[na:1.6.0]
at org.springframework.util.ClassUtils.forName(ClassUtils.java:250) ~[spring-core-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder.findType(DataSourceBuilder.java:121) ~[spring-boot-autoconfigure-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedDataSourceCondition.getDataSourceClassLoader(DataSourceAutoConfiguration.java:197) ~[spring-boot-autoconfigure-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedDataSourceCondition.getMatchOutcome(DataSourceAutoConfiguration.java:183) ~[spring-boot-autoconfigure-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:155) ~[spring-boot-autoconfigure-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.anyMatches(SpringBootCondition.java:138) ~[spring-boot-autoconfigure-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$DataSourceAvailableCondition.getMatchOutcome(DataSourceAutoConfiguration.java:245) ~[spring-boot-autoconfigure-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47) ~[spring-boot-autoconfigure-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:102) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:204) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.processMemberClasses(ConfigurationClassParser.java:337) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:249) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:232) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:510) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:455) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:186) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:321) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:98) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:678) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:520) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:134) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener.initWebApplicationContext(SpringBootContextLoaderListener.java:61) [spring-boot-legacy-1.0.2.RELEASE.jar:1.0.2.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) [spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:1718) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.webcontainer.webapp.WebApp.commonInitializationFinish(WebApp.java:385) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.webcontainer.webapp.WebAppImpl.initialize(WebAppImpl.java:299) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.webcontainer.webapp.WebGroupImpl.addWebApplication(WebGroupImpl.java:100) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.webcontainer.VirtualHostImpl.addWebApplication(VirtualHostImpl.java:166) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.webcontainer.WSWebContainer.addWebApp(WSWebContainer.java:732) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.webcontainer.WSWebContainer.addWebApplication(WSWebContainer.java:617) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.webcontainer.component.WebContainerImpl.install(WebContainerImpl.java:376) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.webcontainer.component.WebContainerImpl.start(WebContainerImpl.java:668) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:1128) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart(DeployedApplicationImpl.java:1319) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:611) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:944) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:741) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.runtime.component.ApplicationMgrImpl$1.run(ApplicationMgrImpl.java:1273) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.security.auth.ContextManagerImpl.runAs(ContextManagerImpl.java:5305) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.security.auth.ContextManagerImpl.runAsSystem(ContextManagerImpl.java:5483) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.security.core.SecurityContext.runAsSystem(SecurityContext.java:255) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplicationDynamically(ApplicationMgrImpl.java:1278) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:2050 ) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:389) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.runtime.component.CompositionUnitImpl.start(CompositionUnitImpl.java:123) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:332) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.startCompositionUnit(CompositionUnitMgrImpl.java:603) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.startCompositionUnit(CompositionUnitMgrImpl.java:565) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:1185) [com.ibm.ws.runtime.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48) ~[na:1.6.0]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0]
at java.lang.reflect.Method.invoke(Method.java:600) ~[na:1.6.0]
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:57) [na:1.6.0]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48) ~[na:1.6.0]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0]
at java.lang.reflect.Method.invoke(Method.java:600) ~[na:1.6.0]
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:260) [na:1.6.0]
at javax.management.modelmbean.RequiredModelMBean$4.run(RequiredModelMBean.java:1137) [na:1.6.0]
at java.security.AccessController.doPrivileged(AccessController.java:250) [na:na]
at com.ibm.oti.security.CheckedAccessControlContext.securityCheck(CheckedAccessControlContext.java:30) [na:2.4 (01-12-2013)]
at sun.misc.JavaSecurityAccessWrapper.doIntersectionPrivilege(JavaSecurityAccessWrapper.java:29) [na:1.6.0]
at javax.management.modelmbean.RequiredModelMBean.invokeMethod(RequiredModelMBean.java:1131) [na:1.6.0]
at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:984) [na:1.6.0]
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836) [na:1.6.0]
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:762) [na:1.6.0]
at com.ibm.ws.management.AdminServiceImpl$1.run(AdminServiceImpl.java:1331) [com.ibm.ws.admin.core.jar:na]
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118) [bootstrap.jar:WAS70.SERV1 [cf291321.01]]
at com.ibm.ws.management.AdminServiceImpl.invoke(AdminServiceImpl.java:1224) [com.ibm.ws.admin.core.jar:na]
at com.ibm.ws.management.application.AppManagementImpl._startApplication(AppManagementImpl.java:1407) [com.ibm.ws.admin.services.jar:na]
at com.ibm.ws.management.application.AppManagementImpl.startApplication(AppManagementImpl.java:1303) [com.ibm.ws.admin.services.jar:na]
at com.ibm.ws.management.application.AppManagementImpl.startApplication(AppManagementImpl.java:1263) [com.ibm.ws.admin.services.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48) ~[na:1.6.0]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0]
at java.lang.reflect.Method.invoke(Method.java:600) ~[na:1.6.0]
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:57) [na:1.6.0]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48) ~[na:1.6.0]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0]
at java.lang.reflect.Method.invoke(Method.java:600) ~[na:1.6.0]
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:260) [na:1.6.0]
at javax.management.modelmbean.RequiredModelMBean$4.run(RequiredModelMBean.java:1137) [na:1.6.0]
at java.security.AccessController.doPrivileged(AccessController.java:250) [na:na]
at com.ibm.oti.security.CheckedAccessControlContext.securityCheck(CheckedAccessControlContext.java:30) [na:2.4 (01-12-2013)]
at sun.misc.JavaSecurityAccessWrapper.doIntersectionPrivilege(JavaSecurityAccessWrapper.java:29) [na:1.6.0]
at javax.management.modelmbean.RequiredModelMBean.invokeMethod(RequiredModelMBean.java:1131) [na:1.6.0]
at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:984) [na:1.6.0]
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836) [na:1.6.0]
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:762) [na:1.6.0]
at com.ibm.ws.management.AdminServiceImpl$1.run(AdminServiceImpl.java:1331) [com.ibm.ws.admin.core.jar:na]
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118) [bootstrap.jar:WAS70.SERV1 [cf291321.01]]
at com.ibm.ws.management.AdminServiceImpl.invoke(AdminServiceImpl.java:1224) [com.ibm.ws.admin.core.jar:na]
at com.ibm.ws.management.connector.AdminServiceDelegator.invoke(AdminServiceDelegator.java:181) [com.ibm.ws.admin.core.jar:na]
at com.ibm.ws.management.connector.ipc.CallRouter.route(CallRouter.java:242) [com.ibm.ws.admin.core.jar:na]
at com.ibm.ws.management.connector.ipc.IPCConnectorInboundLink.doWork(IPCConnectorInboundLink.java:353) [com.ibm.ws.admin.core.jar:na]
at com.ibm.ws.management.connector.ipc.IPCConnectorInboundLink$IPCConnectorReadCallback.complete(IPCConnectorInboundLink.java:595) [com.ibm.ws.admin.core.jar:na]
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175) [com.ibm.ws.runtime.jar:na]
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217) [com.ibm.ws.runtime.jar:na]
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161) [com.ibm.ws.runtime.jar:na]
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138) [com.ibm.ws.runtime.jar:na]
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204) [com.ibm.ws.runtime.jar:na]
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775) [com.ibm.ws.runtime.jar:na]
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1656) [com.ibm.ws.runtime.jar:na]

1 个答案:

答案 0 :(得分:0)

您看到异常的原因与您猜测的完全一样。也就是说,因为您使用的是旧版本的JDK。

好消息是你有选择权。当然,您可以升级JDK,这是可行的解决方案,因为JDK 6已经不再支持并且已经存在了很长时间。

您的另一个选择是包含一个连接池库,不要求您使用高于版本6的JDK。请记住,如果您打算继续使用Spring Boot,您可能会再次遇到同样的问题。

official Spring Boot documentation所述,您可以将自己的DataSource定义为常规Spring bean。您可以使用HikariCP或任何其他符合JDK 6的库。我建议不要使用旧版本的Tomcat连接池来避免名称冲突。