2017-08-08 10 views
0

バネレストAPIガイドをスプリングブートと単純なMVCタイプのアプリケーションで使用すると、単純なGETでは404が見つかりません。間違った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

あなたが「/」の追加を持って、ちょうどクラスレベルで

@Controller 
@RequestMapping("") 
public class UserController { 
を@RequestMappingから削除
関連する問題