2017-08-08 82 views
0

使用spring rest API引导了spring引导和简单的MVC类型应用程序,结果在404中找不到简单的GET。我已经搜索了从不正确的web.xml内容到servlet-context.xml条目的响应,我无法找到问题的根源。其余api指南失败404未找到或者tomcat服务器失败

的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:web="http://java.sun.com/xml/ns/javaee" 
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" version="2.5"> 
<context-param> 
<param-name>contextConfigLocation</param-name> 
<param-value>/WebContent/WEB-INF/spring-servlet.xml</param-value> 
</context-param> 
<listener> 
<listener- 
class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 
<listener> 
<listener-class> 
    org.springframework.web.context.request.RequestContextListener 
</listener-class> 
</listener> 

<servlet-mapping> 
<servlet-name>api</servlet-name> 
<url-pattern>/</url-pattern> 
</servlet-mapping> 
<context-param> 
<param-name>defaultHtmlEscape</param-name> 
<param-value>true</param-value> 
</context-param> 
<filter> 
<filter-name>springSecurityFilterChain</filter-name> 
<filter-class> 
       org.springframework.web.filter.DelegatingFilterProxy 
</filter-class> 
</filter> 
<filter-mapping> 
<filter-name>springSecurityFilterChain</filter-name> 
<url-pattern>/*</url-pattern> 
</filter-mapping> 
</web-app> 

的context.xml

<?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" 
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/context/ 
    http://www.springframework.org/schema/context/spring-context.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc.xsd"> 

<context:component-scan base-package="com.restservice.controllers" /> 
<mvc:annotation-driven /> 

</beans> 

控制器文件

@Controller 
@RequestMapping("/") 
public class UserController { 

    @RequestMapping(value = "/greeting", method = RequestMethod.GET) 
    public @ResponseBody Greeting greeting(@RequestParam(value="name", 
    defaultValue="World") String name, HttpServletResponse httpResponse_p, 
              WebRequest request_p) { 
     return new Greeting(counter.incrementAndGet(), 
          String.format(template, name)); 
    } 

    } 

第一Tomcat服务器无法启动。如果我删除服务器并重新创建,重新启动然后服务器启动罚款。然后我尝试运行应用程序,服务器无法启动。

关闭应用程序并重新打开一次,但随后出现404。

回答

1

你有一个额外的“/”,只是从一流水平@RequestMapping删除

@Controller 
@RequestMapping("") 
public class UserController { 
相关问题