2013-07-23 97 views
1

我試圖使用Spring創建REST Web服務。Spring REST Web服務appContext失敗

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

控制器:

@Controller 
public class RestController { 

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

//some logic here 

} 

和APP方面:

<?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,試圖啓動GET異常時:

[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 

利布斯,我用 - Spring beans,core,context,web,webmvc,security-core,oxm。 P.S.之前從未使用Spring,所以我不知道有什麼錯。

有什麼建議嗎?

回答

2

您錯過了Spring expression JAR file

既然你已經擁有了Spring的核心JAR文件,你應該如果使用的是項目生成管理,如Mavenspring-expressionspring-core依賴有表達JAR文件。在這種情況下,部署表達式JAR文件時可能會出現問題(或者它不存在於本地Maven存儲庫中,或者已損壞)。請參閱here如何刷新本地Maven存儲庫。

如果您不使用Maven等構建管理器,那麼您需要手動下載JAR文件,並將該版本與現有的Spring JAR文件進行匹配。

+0

是的,你說得對。現在,它的工作,謝謝。 –

1

如果您的主要興趣是創建RESTful服務,您可能需要考慮在Spring中使用RESTEasy。我最近寫了這個article關於如何使用Spring設置RESTEasy的工作代碼庫。