Spring REST Web服务appContext失败

时间:2013-07-23 10:15:15

标签: java spring web-services rest

我正在尝试使用Spring创建REST Web服务。

我有一个控制器,一个appContext。

控制器:

@Controller
public class RestController {

@RequestMapping(method=RequestMethod.POST, value="service/{url}......<params>) 
//some method here

//some logic here

}

应用程序上下文:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="
                http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                http://www.springframework.org/schema/context 
                http://www.springframework.org/schema/context/spring-context-3.0.xsd">

        <context:component-scan base-package="spring.rest.controller" />

        <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
        <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

</beans>

我在尝试启动异常时使用Tomcat 7:

[13:02] ERROR ContextLoader () - Context initialization failed
java.lang.NoClassDefFoundError: org/springframework/expression/PropertyAccessor
    at org.springframework.context.support.AbstractApplicationContext.prepareBeanFactory(AbstractApplicationContext.java:567)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:468)
    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:106)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassNotFoundException: org.springframework.expression.PropertyAccessor
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    ... 15 more
Jul 23, 2013 1:02:21 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: org/springframework/expression/PropertyAccessor
    at org.springframework.context.support.AbstractApplicationContext.prepareBeanFactory(AbstractApplicationContext.java:567)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:468)
    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:106)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassNotFoundException: org.springframework.expression.PropertyAccessor
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    ... 15 more

我使用的Libs - Spring bean,core,context,web,webmvc,security-core,oxm。 附:从来没用过Spring,所以我不知道出了什么问题。

有什么建议吗?

2 个答案:

答案 0 :(得分:2)

你错过了Spring expression JAR file

由于您已经拥有Spring核心JAR文件,因此如果Maven使用项目构建管理器({1}}是spring-expression的依赖项,则应该具有表达式JAR文件。在这种情况下,可能是部署表达式JAR文件时出现问题(它在本地Maven存储库中不存在或者已损坏)。请参阅here如何刷新本地Maven存储库。

如果您没有使用Maven等构建管理器,那么您需要手动下载JAR文件,将该版本与现有的Spring JAR文件相匹配。

答案 1 :(得分:1)

如果您的主要兴趣是创建RESTful服务,您可能需要考虑在Spring中使用RESTEasy。我最近写了这个article,其中有一个关于如何使用Spring设置RESTEasy的工作代码库。