2016-12-02 30 views
0

私の最初の春のmvcアプリケーションで404エラーが発生しました。すべての設定に続いて運がありません。あなたは問題を理解するのを手伝ってもらえますか?org.springframework.web.servlet.PageNotFoundを取得するnoHandlerFoundエラー

Following is the change: 

の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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> 
    <display-name>HereWeGo</display-name> 


    <display-name>HereWeGo</display-name> 
    <servlet> 
     <servlet-name>spring-dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>spring-dispatcher</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 


</web-app> 

ばねディスパッチャ-servlet.xml

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

    <mvc:annotation-driven /> 

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
      <property name="prefix"> 
       <value>/WEB-INF/</value> 
      </property> 
      <property name="suffix"> 
       <value>.jsp</value> 
      </property> 
    </bean> 

</beans> 

HeyThere.java

サーバーコンソールで0

Hello.jspの

<html> 
<body> 
    <h1>First Spring MVC Application Demo</h1> 
    <h2>${welcomeMessage}</h2> 
</body> 
</html> 

私は警告の下に取得しています:

org.springframework.web.servlet.PageNotFound noHandlerFound 

WARNING: No mapping found for HTTP request with URI [/HereWeGo/] in DispatcherServlet with name 'spring-dispatcher' 

私のプロジェクト名はHereWeGoです。

答えて

0

あなたの設定は、あなたの<mvc:annotation-driven />タグと同じように行います(Javaの構成に固有のものです)@EnableWebMvc注釈を除いて、[OK]を探します。(ここでは参考EnableWebMvc annotation meaning

また、この問題に対する修正、に記載されているようにスプリングアプリケーションコンテキストでコントローラを登録するための<mvc:annotation-driven>タグの後に、 <context:component-scan base-package="com.aditya.spring" /> spring-dispatcher-servlet.xmlを追加する必要があります。

あなたのコントローラは/ welcomeにマップされているので、 localhost:<YourServerPort>/<YourWebAppDeployName>/welcomeにコントローラメソッドを入力し、jsp-viewにアクセスするようにしてください。

+0

指定した注釈が削除され、「/ welcome」でアクセスされ、次のエラーで同じ応答が返されます。 ** org.springframework.web.servlet.PageNotFound noHandlerFound ** ** WARNING:名 '春-ディスパッチャ' でのDispatcherServletにURI [/ HereWeGoは/歓迎]でHTTPリクエストが見つかりませんマッピング** –

+0

してくださいlocalhost:8080/com.aditya.spring/welcome 8080があなたのサーバポートである場合に歓迎してください。その場合は –

+0

運がないことを教えてください。も404ページを与えています。 –

関連する問題