开发者

Using @PostConstruct annotation in Spring 3.0.0.RC1

I am using @PostConstruct annotation (to mark init method in a bean) in Spring version 3.0.0.RC1. I start this web application in Jetty and get the following exception:

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(开发者_如何学JAVANative 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

Does anybody knows if it is a bug in RC1 or if there is a work around?


I know this is an old question, but I'll still post the answer that I found for the sake of posterity.

This is a dependency issue. In my project's dependency tree, I noticed that the cxf-rt-transports-http-jetty dependency had a transitive dependency on spring-web.2.5.5. The OrderComparator.sort method wasn't implemented until later, so unless you add a direct dependency definition for a newer version of spring-web to your POM, spring will fall back to the older version that jetty needs.

To fix this, I added dependency definitions for the latest spring-core and spring-web artifacts to my POM.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜