2014-03-07 49 views
0

我是新来的春天restfull服务。我知道我在这方面犯了一些错误。但我无法识别这些。我不知道接下来应该做什么。请推荐以下内容:Spring Restful Services示例显示错误..!

  • 是否需要添加任何库文件?我已经添加springjars & springcorejars
  • 我在​​文件中出现错误。
  • 如果可能的话,使用Spring Framework为restfull服务提供一个合适的教程。

我刚添加的屏幕芽和下面的代码:

StateController.java

package com.spring.restful; 

import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.PathVariable; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.ResponseBody; 
@Controller 
@RequestMapping("/state") 
public class StateController { 
    @RequestMapping(value = "/{code}", method = RequestMethod.GET) 
    public @ResponseBody String getState(@PathVariable String code) { 
     String result; 
     if (code.equals("KL")) { 
      result = "Kerala"; 
     } else { 
      result = "Default State"; 
     } 
     return result; 
    } 
} 

调度-servlet.xml中

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:p="http://www.springframework.org/schema/p" 
    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 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 
    <context:component-scan base-package="com.pretech" /> 
    <mvc:annotation-driven /> 
    </beans> 

的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> 
    <display-name>SpringRestFulExample</display-name> 
    <servlet> 
    <servlet-name>dispatcher</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
    <servlet-name>dispatcher</servlet-name> 
    <url-pattern>/</url-pattern> 
    </servlet-mapping> 
</web-app> 

Screen Shoot of the error page

建议您的想法... !!!

回答

1

复制春库放到WEB-INF/lib目录 - >选择所有库 - >右键 - >构建路径 - >添加到构建路径 - >它完成

你可以从这个链接下载春瓶 - >link

有不同的版本,你最好下载版本3和更高版本,因为它们完全支持基于Spring Annotations!你的下载完成后,你提取zip文件,每个包可能有3个不同的jar文件。示例spring core:(lib/bin,source,doc)。您只需要将lib/bin库复制到您的WEB-INF/lib文件夹中即可!

如果您有任何问题,请随时询问!

0

也发布您的pom.xml。我在截图中找不到它,但您似乎正在使用Maven构建。 您是否添加了其他必需的罐子,如弹簧网等?

+0

我没有找到任何pom.xml文件。我试图执行这个[链接]的例子(http://www.pretechsol.com/2013/08/spring-restful-web-services-example.html#.UxlNg_mSyT8)请检查这个例子,并建议我。 。 – TDJSS