在Spring 3.0.0.RC1中使用@PostConstruct注释

时间:2009-10-26 18:59:19

标签: spring

我在Spring版本3.0.0.RC1中使用@PostConstruct注释(在bean中标记init方法)。我在Jetty中启动此Web应用程序并获得以下异常:

java.lang.NoSuchMethodError: org.springframework.core.OrderComparator.sort(Ljava/util/List;)V
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:520)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:366)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:270)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
    at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1234)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:460)
    at org.gradle.api.plugins.jetty.JettyPluginWebAppContext.doStart(JettyPluginWebAppContext.java:140)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
    at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.Server.doStart(Server.java:222)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.gradle.api.plugins.jetty.JettyPluginServer.start(JettyPluginServer.java:128)
    at org.gradle.api.plugins.jetty.AbstractJettyRunTask.startJettyInternal(AbstractJettyRunTask.java:290)
    at org.gradle.api.plugins.jetty.AbstractJettyRunTask.startJetty(AbstractJettyRunTask.java:245)
    at org.gradle.api.plugins.jetty.AbstractJettyRunTask.start(AbstractJettyRunTask.java:216)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1049)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:880)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:706)
    at org.gradle.api.DefaultTask.invokeMethod(DefaultTask.groovy)
    at groovy.lang.GroovyObject$invokeMethod.call(Unknown Source)
    at org.gradle.util.ReflectionUtil.invoke(ReflectionUtil.groovy:23)
    at org.gradle.api.internal.project.AnnotationProcessingTaskFactory$2.execute(AnnotationProcessingTaskFactory.java:125)
    at org.gradle.api.internal.project.AnnotationProcessingTaskFactory$2.execute(AnnotationProcessingTaskFactory.java:123)
    at org.gradle.api.internal.AbstractTask.doExecute(AbstractTask.java:257)
    at org.gradle.api.internal.AbstractTask.execute(AbstractTask.java:222)
    at org.gradle.execution.DefaultTaskExecuter.executeTask(DefaultTaskExecuter.java:165)
    at org.gradle.execution.DefaultTaskExecuter.doExecute(DefaultTaskExecuter.java:156)
    at org.gradle.execution.DefaultTaskExecuter.execute(DefaultTaskExecuter.java:74)
    at org.gradle.execution.TaskNameResolvingBuildExecuter.execute(TaskNameResolvingBuildExecuter.java:174)
    at org.gradle.execution.DelegatingBuildExecuter.execute(DelegatingBuildExecuter.java:54)
    at org.gradle.GradleLauncher.doBuildStages(GradleLauncher.java:165)
    at org.gradle.GradleLauncher.doBuild(GradleLauncher.java:124)
    at org.gradle.GradleLauncher.run(GradleLauncher.java:95)
    at org.gradle.Main.execute(Main.java:100)
    at org.gradle.Main.main(Main.java:43)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.gradle.BootstrapMain.main(BootstrapMain.java:50)
failed ContextHandlerCollection@1a88001

有人知道这是RC1中的错误还是有解决方法?

1 个答案:

答案 0 :(得分:1)

我知道这是一个老问题,但我仍会发布我为后代发现的答案。

这是依赖性问题。在我的项目的依赖树中,我注意到cxf-rt-transports-http-jetty依赖关系对spring-web.2.5.5具有传递依赖性。 OrderComparator.sort方法直到稍后才实现,所以除非你为你的POM添加一个更新版本的spring-web的直接依赖关系定义,spring将回退到jetty需要的旧版本。

为了解决这个问题,我将最新的spring-core和spring-web工件的依赖项定义添加到了我的POM中。