【发布时间】:2015-02-18 17:17:03
【问题描述】:
我是 spring 新手,我正在使用 spring 制作一个小项目。我在运行项目时遇到错误。下面是我的控制器、rest-servlet-xml 和 web.xml。我找不到什么样的错误。我在我的 ECLIPSE 中使用 JBOSS6
package com.webService.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.RestController;
@RestController
@RequestMapping("/service/greeting")
public class SpringServiceController {
@RequestMapping(value = "/{name}", method = RequestMethod.GET)
public String getGreeting(@PathVariable String name) {
String result="Hello "+name;
return result;
}
}
<?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-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<context:component-scan base-package="com.webService.controller" />
<mvc:annotation-driven />
</beans>
<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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>SpringServiceSample</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
【问题讨论】:
-
您能发布您的应用程序上下文吗?检查:dineshonjava.com/2014/02/…
-
什么是我没用过的,我按照网上给出的步骤做了这个简单的项目。没有提到任何东西
-
亲爱的 Partick,我已经检查了所有和我一样的东西,但是在我的 Eclipse 中运行时我没有发现错误,它工作正常,但是在使用 jboss6 运行时它给了我这样的错误
-
我看到了,服务器有日志可以分享吗?您在 eclipse 中使用的是哪个服务器?
标签: spring-mvc