我是新来的春天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>
建议您的想法... !!!
我没有找到任何pom.xml文件。我试图执行这个[链接]的例子(http://www.pretechsol.com/2013/08/spring-restful-web-services-example.html#.UxlNg_mSyT8)请检查这个例子,并建议我。 。 – TDJSS