Spring 升级到 Java 8 时出现 IllegalStateExceptions

Spring IllegalStateExceptions when upgrading to Java 8

对此很陌生,但我正在尝试从 java 6 升级到 java 8。

我使用 java 8 构建。它编译正常,但在运行应用程序时出现一些服务器错误。我读到 java 8 需要 spring 升级到版本 4,所以我按照 this 指南进行了升级。经过一番心痛之后,一切都重新编译了,但我仍然遇到错误。我知道这仍然是一个版本控制问题,但我不确定从哪里开始尝试找出位置...

我正在运行 tomcat 6.0.33,java 8(希望),spring 4(也希望),它是一个 RESTful 网络服务。

我已更新 tomcat 以运行 java 8,并且我的路径变量是最新的。

谢谢水桶!这是完整的跟踪。

2015-01-07 14:53:54.270 ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
java.lang.IllegalArgumentException
    at org.springframework.asm.ClassReader.<init>(Unknown Source)
    at org.springframework.asm.ClassReader.<init>(Unknown Source)
    at org.springframework.asm.ClassReader.<init>(Unknown Source)
    at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:52)
    at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
    at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102)
    at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:76)
    at org.springframework.context.annotation.ConfigurationClassUtils.checkConfigurationClassCandidate(ConfigurationClassUtils.java:70)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:253)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:223)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:630)
    at org.springframework.context.support.AbstractApplicationContext.__refresh(AbstractApplicationContext.java:461)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)
    at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Jan 07, 2015 2:53:54 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
Jan 07, 2015 2:53:54 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [] startup failed due to previous errors
2015-01-07 14:53:54.345 INFO : org.springframework.web.context.support.XmlWebApplicationContext - Closing Root WebApplicationContext: startup date [Wed Jan 07 14:53:45 GMT 2015]; root of context hierarchy
2015-01-07 14:53:54.354 WARN : org.springframework.web.context.support.XmlWebApplicationContext - Exception thrown from ApplicationListener handling ContextClosedEvent
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: Root WebApplicationContext: startup date [Wed Jan 07 14:53:45 GMT 2015]; root of context hierarchy
    at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:347)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:334)
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1049)
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1010)
    at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:558)
    at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:143)
    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4245)
    at org.apache.catalina.core.StandardContext.__stop(StandardContext.java:4886)
    at org.apache.catalina.core.StandardContext.stop(StandardContext.java)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4750)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)
    at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
2015-01-07 14:53:54.357 WARN : org.springframework.web.context.support.XmlWebApplicationContext - Exception thrown from LifecycleProcessor on context close
java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: Root WebApplicationContext: startup date [Wed Jan 07 14:53:45 GMT 2015]; root of context hierarchy
    at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:360)
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1057)
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1010)
    at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:558)
    at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:143)
    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4245)
    at org.apache.catalina.core.StandardContext.__stop(StandardContext.java:4886)
    at org.apache.catalina.core.StandardContext.stop(StandardContext.java)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4750)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)
    at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

编辑: 所以我试图从我的项目中删除 asm

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
            <exclusions>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-asm</artifactId>
            </exclusion>
        </exclusions>
        </dependency>
        <!-- <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-asm</artifactId>
            <version>${spring.version}</version>
        </dependency> -->

但我仍然得到

ERROR: org.springframework.web.context.ContextLoader - Context initialization failed java.lang.IllegalArgumentException at org.springframework.asm.ClassReader.<init>(Unknown Source)...

我现在也在用tomcat8

我查看了所有子 pom 并添加了对任何引用 asm 的排除项。 我不知道为什么叫这个...

有没有人有什么想法?

编辑 2: 运行 mvn dependency:tree 后,这里是输出的 asm 相关部分(输出本身很大,所以我不想 post 全部)

[INFO] com.gustavo:maven-j2as-plugin:maven-plugin:1.0.0-SNAPSHOT
[INFO] +- org.apache.maven:maven-plugin-api:jar:3.1.0:compile
[INFO] |  +- org.apache.maven:maven-model:jar:3.1.0:compile
[INFO] |  |  \- org.codehaus.plexus:plexus-utils:jar:3.0.10:compile
[INFO] |  +- org.apache.maven:maven-artifact:jar:3.1.0:compile
[INFO] |  \- org.eclipse.sisu:org.eclipse.sisu.plexus:jar:0.0.0.M2a:compile
[INFO] |     +- javax.enterprise:cdi-api:jar:1.0:compile
[INFO] |     |  +- javax.annotation:jsr250-api:jar:1.0:compile
[INFO] |     |  \- javax.inject:javax.inject:jar:1:compile
[INFO] |     +- org.sonatype.sisu:sisu-guice:jar:no_aop:3.1.0:compile
[INFO] |     +- org.eclipse.sisu:org.eclipse.sisu.inject:jar:0.0.0.M2a:compile
[INFO] |     |  \- asm:asm:jar:3.3.1:compile

[INFO] com.gustavo:maven-j2as-plugin:maven-plugin:1.0.0-SNAPSHOT
[INFO] +- org.apache.maven:maven-plugin-api:jar:3.1.0:compile
[INFO] |  +- org.apache.maven:maven-model:jar:3.1.0:compile
[INFO] |  |  \- org.codehaus.plexus:plexus-utils:jar:3.0.10:compile
[INFO] |  +- org.apache.maven:maven-artifact:jar:3.1.0:compile
[INFO] |  \- org.eclipse.sisu:org.eclipse.sisu.plexus:jar:0.0.0.M2a:compile
[INFO] |     +- javax.enterprise:cdi-api:jar:1.0:compile
[INFO] |     |  +- javax.annotation:jsr250-api:jar:1.0:compile
[INFO] |     |  \- javax.inject:javax.inject:jar:1:compile
[INFO] |     +- org.sonatype.sisu:sisu-guice:jar:no_aop:3.1.0:compile
[INFO] |     +- org.eclipse.sisu:org.eclipse.sisu.inject:jar:0.0.0.M2a:compile
[INFO] |     |  \- asm:asm:jar:3.3.1:compile

[INFO] +- cglib:cglib:jar:2.2:compile
[INFO] |  \- asm:asm:jar:3.1:compile

[INFO] +- cglib:cglib:jar:2.2:compile
[INFO] |  \- asm:asm:jar:3.1:compile

[INFO] +- cglib:cglib:jar:2.2:compile
[INFO] |  \- asm:asm:jar:3.1:compile

[INFO] +- cglib:cglib:jar:2.2:compile
[INFO] |  \- asm:asm:jar:3.1:compile

[INFO] |  +- cglib:cglib:jar:2.2:compile
[INFO] |  |  \- asm:asm:jar:3.1:compile

[INFO] |  +- cglib:cglib:jar:2.2:compile
[INFO] |  |  \- asm:asm:jar:3.1:compile

[INFO] |  +- xml-resolver:xml-resolver:jar:1.2:compile
[INFO] |  +- asm:asm:jar:3.3:compile

[INFO] |  +- xml-resolver:xml-resolver:jar:1.2:compile
[INFO] |  +- asm:asm:jar:3.3:compile

[INFO] +- cglib:cglib:jar:2.2:runtime
[INFO] |  \- asm:asm:jar:3.1:compile

[INFO] +- cglib:cglib:jar:2.2:runtime
[INFO] |  \- asm:asm:jar:3.1:compile

我有 30 个模块,所以我猜其中 12 个仍然依赖于 asm:/

Tomcat 6 不支持 Java 8,您可能需要先将 tomcat 版本升级到 9 一些东西: http://tomcat.apache.org/whichversion.html

我有一个旧版本的 webflow,它对 Spring

的旧版本有传递依赖