2017-06-12 19 views
-1

私はSpring MVCのを学ぶために始めているが、私は私のプログラムを実行すると、私は次のようなエラーになっています:SpringMVC HTTPステータス404 -

HTTP Status 404 - type Status report message description The requested resource is not available. Apache Tomcat/8.0.41

web.xmlの

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
     version="3.1"> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/applicationContext.xml</param-value> 
    </context-param> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 
    <servlet> 
     <servlet-name>springmvc</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>/WEB-INF/springmvc-servlet.xml</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>springmvc</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 
</web-app> 

springmvc-servlet.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-3.2.xsd 
     http://www.springframework.org/schema/cache 
     http://www.springframework.org/schema/cache/spring-cache.xsd"> 

    <context:component-scan base-package="com"/> 
    <mvc:annotation-driven/> 
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="/WEB-INF/view/"/> 
     <property name="suffix" value=".jsp"/> 
    </bean> 
</beans> 

SpringTest.java

package com; 

import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 

@Controller 
@RequestMapping("/home") 
public class SpringTest { 
    @RequestMapping(value = "/home",method =RequestMethod.GET) 
    public String home(){ 
     return "home"; 
    } 
} 

次のように私のプロジェクト構造がある:私は、この手順を実行するためのIntelliJ IDEAを使用

enter image description here

。 IntelliJ IDEAが私が得ているエラーの理由ですか?

+0

それはときに失敗しませんあなたはプログラムを実行します。 HTTP要求を送信すると失敗します。どのようなHTTPリクエストを送信しましたか? –

+0

私はテストするためにTomcatを使用します。私は私のsendにHTTPリクエストを知らない –

答えて

0

<context:component-scan base-package="com"/><mvc:annotation-driven/>間の秩序作りを変更するください<mvc:annotation-driven/>あなたは、以下のコードで、あなたのコントローラを交換してみてください${ContextPath}/home/homeにアクセスしようとしている最初の

@Controller 
public class SpringTest { 
    @RequestMapping(value = "/home",method =RequestMethod.GET) 
    public String home(){ 
     return "home"; 
    } 
} 
+0

ありがとうございます。しかし、私はそれを試した後でもありません。私は夢中になります –

関連する問題