我已经挣扎了四个小时。
我有一个如此定义的控制器。
package handlers.site2;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@Controller
@RequestMapping(value = "/site", method = RequestMethod.GET)
public class Site2 {
public enum Status {
ERROR
}
public static class CommonRO {
protected Status status;
protected String description;
}
public static class SiteRO extends CommonRO {
private Integer siteId;
private Integer companyId;
private String siteName;
private Integer siteStatusId;
private String customerSiteId;
private Integer timeZoneRuleId;
}
public static class CommonDTO {
private String authToken;
}
public static class SiteDTO extends CommonDTO {
private Integer siteId;
}
@RequestMapping(value = "/", method = RequestMethod.GET)
@ResponseBody
public String index() {
return "Hello";
}
@RequestMapping(value = "/getSite", method = RequestMethod.GET)
@ResponseBody
public SiteRO getSite(Integer siteId, String authToken) {
SiteRO response = new SiteRO();
response.siteName = "Test";
return response;
}
}
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" 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>testapp</display-name>
<listener>
<listener-class>main.StartUpConfiguration</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<display-name>Generic Rest API</display-name>
<servlet-name>GenericRestAPI</servlet-name>
<servlet-class>corewebapi.controller</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>GenericRestAPI</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<servlet>
<display-name>Apache-Axis Servlet</display-name>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>*.jws</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet>
<display-name>Apache-Axis Admin Servlet Web Admin</display-name>
<servlet-name>AxisAdminServlet</servlet-name>
<servlet-class>org.apache.axis2.webapp.AxisAdminServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AxisAdminServlet</servlet-name>
<url-pattern>/axis2-admin/*</url-pattern>
</servlet-mapping>
<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>/rest2/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>
</web-app>
和dispatcher-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"
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">
<mvc:annotation-driven/>
<context:component-scan base-package="handlers.site2"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
我启用了spring mvc中的日志记录,看到确实找到了我的控制器(因此检测到了@Controller),但后来我看到了[DEBUG]拒绝的bean名称&#39; site2&#39;:没有识别出URL路径。&#39;当我尝试使用/ testapp / rest2 / site或/ testapp / rest2 / site / getSite联系服务时,我收到错误消息
[DEBUG] DispatcherServlet with name 'dispatcher' processing GET request for [/testapp/rest2/site/getSite]
[TRACE] Testing handler map [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@1c7ab89d] in DispatcherServlet with name 'dispatcher'
[DEBUG] Looking up handler method for path /site/getSite
[DEBUG] Did not find handler method for [/site/getSite]
[TRACE] Testing handler map [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@3cee5a06] in DispatcherServlet with name 'dispatcher'
[TRACE] No handler mapping found for [/site/getSite]
[WARN] No mapping found for HTTP request with URI [/testapp/rest2/site/getSite] in DispatcherServlet with name 'dispatcher'
请求:http://:8080 / testapp / rest2 / site / getSite?siteId = 50&amp; authToken = abdf
其他信息:从eclipse部署到tomcat 6. jdk6 update 45。
有什么想法吗?