2017-08-08 80 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 { 
相關問題