2016-03-26 13 views
0

私は単純なSpring MVC web app.Iを実装しようとしています。Eclipseでプロジェクトを構築します。 そしてTomcat経由でのデプロイ時にこのエラーが発生します。hello world appのHTTP 404エラーコード

エラーコード: enter image description here

フォルダ構造 enter image description here のWeb.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 

    <display-name>Theka Desi Khana</display-name> 
    <!-- The definition of the Root Spring Container shared by all Servlets and Filters --> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring/root-context.xml</param-value> 
    </context-param> 

    <!-- Creates the Spring Container shared by all Servlets and Filters --> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

    <!-- Processes application requests --> 
    <servlet> 
     <servlet-name>appServlet</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>appServlet</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 
    <welcome-file-list> 
    <welcome-file>index.jsp</welcome-file> 
    </welcome-file-list> 
</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" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> 


</beans> 

サーブレットのcontext.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/mvc" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd 
     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"> 

    <!-- DispatcherServlet Context: defines this servlet's request-processing 
     infrastructure --> 

    <context:component-scan base-package="com.theka.desi.Controllers" /> 



    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --> 

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


    <!-- Handles HTTP GET requests for /resources/** by efficiently serving 
     up static resources in the ${webappRoot}/resources directory --> 
    <resources mapping="/resources/**" location="/resources/" />  




</beans:beans> 

にHomeController

package com.theka.desi.Controllers; 


import javax.servlet.ServletContext; 

import org.apache.log4j.Logger; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.servlet.ModelAndView; 
@Controller 
@RequestMapping("/") 
public class HomeController { 
    @Autowired 
    private ServletContext servletContext; 
    private final Logger logger = Logger.getLogger(HomeController.class); 

    public ServletContext getServletContext() { 
     return servletContext; 
    } 

    public void setServletContext(ServletContext servletContext) { 
     this.servletContext = servletContext; 
    } 



    @RequestMapping("/") 
     public String welcome() { 
      return "redirect:/home"; 
     } 

     @RequestMapping("/home") 
     public ModelAndView home() { 
      ModelAndView view = new ModelAndView("index"); 

      return view; 
     } 






} 

コンソールログ:

Mar 26, 2016 6:09:56 PM org.apache.tomcat.util.digester.SetPropertiesRule begin 
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:desi' did not find a matching property. 
Mar 26, 2016 6:09:56 PM org.apache.catalina.startup.VersionLoggerListener log 
INFO: Server version:  Apache Tomcat/7.0.65 
Mar 26, 2016 6:09:56 PM org.apache.catalina.startup.VersionLoggerListener log 
INFO: Server built:   Oct 9 2015 08:36:58 UTC 
Mar 26, 2016 6:09:56 PM org.apache.catalina.startup.VersionLoggerListener log 
INFO: Server number:   7.0.65.0 
Mar 26, 2016 6:09:56 PM org.apache.catalina.startup.VersionLoggerListener log 
INFO: OS Name:    Windows 8.1 
Mar 26, 2016 6:09:56 PM org.apache.catalina.startup.VersionLoggerListener log 
INFO: OS Version:   6.3 
Mar 26, 2016 6:09:56 PM org.apache.catalina.startup.VersionLoggerListener log 
INFO: Architecture:   amd64 
Mar 26, 2016 6:09:56 PM org.apache.catalina.startup.VersionLoggerListener log 
INFO: Java Home:    C:\Program Files\Java\jdk1.7.0_79\jre 
Mar 26, 2016 6:09:56 PM org.apache.catalina.startup.VersionLoggerListener log 
INFO: JVM Version:   1.7.0_79-b15 
Mar 26, 2016 6:09:56 PM org.apache.catalina.startup.VersionLoggerListener log 
INFO: JVM Vendor:   Oracle Corporation 
Mar 26, 2016 6:09:56 PM org.apache.catalina.startup.VersionLoggerListener log 
INFO: CATALINA_BASE:   C:\Users\nand\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0 
Mar 26, 2016 6:09:56 PM org.apache.catalina.startup.VersionLoggerListener log 
INFO: CATALINA_HOME:   G:\Softy\apache-tomcat-7.0.65-windows-x64\apache-tomcat-7.0.65 
Mar 26, 2016 6:09:56 PM org.apache.catalina.startup.VersionLoggerListener log 
INFO: Command line argument: -Dcatalina.base=C:\Users\nand\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0 
Mar 26, 2016 6:09:56 PM org.apache.catalina.startup.VersionLoggerListener log 
INFO: Command line argument: -Dcatalina.home=G:\Softy\apache-tomcat-7.0.65-windows-x64\apache-tomcat-7.0.65 
Mar 26, 2016 6:09:56 PM org.apache.catalina.startup.VersionLoggerListener log 
INFO: Command line argument: -Dwtp.deploy=C:\Users\nand\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps 
Mar 26, 2016 6:09:56 PM org.apache.catalina.startup.VersionLoggerListener log 
INFO: Command line argument: -Djava.endorsed.dirs=G:\Softy\apache-tomcat-7.0.65-windows-x64\apache-tomcat-7.0.65\endorsed 
Mar 26, 2016 6:09:56 PM org.apache.catalina.startup.VersionLoggerListener log 
INFO: Command line argument: -Dfile.encoding=Cp1252 
Mar 26, 2016 6:09:56 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent 
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.7.0_79\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Git\cmd;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Common Files\lenovo\easyplussdk\bin;C:\Program Files (x86)\Skype\Phone\;. 
Mar 26, 2016 6:09:56 PM org.apache.coyote.AbstractProtocol init 
INFO: Initializing ProtocolHandler ["http-bio-8080"] 
Mar 26, 2016 6:09:56 PM org.apache.coyote.AbstractProtocol init 
INFO: Initializing ProtocolHandler ["ajp-bio-8009"] 
Mar 26, 2016 6:09:56 PM org.apache.catalina.startup.Catalina load 
INFO: Initialization processed in 1234 ms 
Mar 26, 2016 6:09:56 PM org.apache.catalina.core.StandardService startInternal 
INFO: Starting service Catalina 
Mar 26, 2016 6:09:56 PM org.apache.catalina.core.StandardEngine startInternal 
INFO: Starting Servlet Engine: Apache Tomcat/7.0.65 
Mar 26, 2016 6:09:59 PM org.apache.catalina.startup.TldConfig execute 
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 
Mar 26, 2016 6:09:59 PM org.apache.catalina.core.ApplicationContext log 
INFO: No Spring WebApplicationInitializer types detected on classpath 
Mar 26, 2016 6:09:59 PM org.apache.catalina.core.ApplicationContext log 
INFO: Initializing Spring root WebApplicationContext 
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader). 
log4j:WARN Please initialize the log4j system properly. 
Mar 26, 2016 6:09:59 PM org.apache.catalina.core.ApplicationContext log 
INFO: Initializing Spring FrameworkServlet 'appServlet' 
Mar 26, 2016 6:10:00 PM org.apache.coyote.AbstractProtocol start 
INFO: Starting ProtocolHandler ["http-bio-8080"] 
Mar 26, 2016 6:10:00 PM org.apache.coyote.AbstractProtocol start 
INFO: Starting ProtocolHandler ["ajp-bio-8009"] 
Mar 26, 2016 6:10:00 PM org.apache.catalina.startup.Catalina start 
INFO: Server startup in 4357 ms 
Mar 26, 2016 6:10:50 PM org.apache.catalina.loader.WebappClassLoaderBase modified 
SEVERE:  Resource '/WEB-INF/classes/com/theka/desi/Controllers/HomeController.class' is missing 
Mar 26, 2016 6:10:50 PM org.apache.catalina.core.StandardContext reload 
INFO: Reloading Context with name [/desi] has started 
Mar 26, 2016 6:10:50 PM org.apache.catalina.core.ApplicationContext log 
INFO: Destroying Spring FrameworkServlet 'appServlet' 
Mar 26, 2016 6:10:50 PM org.apache.catalina.core.ApplicationContext log 
INFO: Closing Spring root WebApplicationContext 
Mar 26, 2016 6:10:52 PM org.apache.catalina.startup.TldConfig execute 
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 
Mar 26, 2016 6:10:52 PM org.apache.catalina.core.ApplicationContext log 
INFO: No Spring WebApplicationInitializer types detected on classpath 
Mar 26, 2016 6:10:52 PM org.apache.catalina.core.ApplicationContext log 
INFO: Initializing Spring root WebApplicationContext 
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader). 
log4j:WARN Please initialize the log4j system properly. 
Mar 26, 2016 6:10:53 PM org.apache.catalina.core.ApplicationContext log 
INFO: Initializing Spring FrameworkServlet 'appServlet' 
Mar 26, 2016 6:10:53 PM org.apache.catalina.core.StandardContext reload 
INFO: Reloading Context with name [/desi] is completed 

サーバで実行私は> Prject_としてプロジェクトを実行したとして実行 enter image description here

展開ディレクトリ構造>

+0

私は、ログを追加した@andy catalina.out – andy

+0

のいずれかのログ。ログ関連のマッピングはありません。 – nand

+2

ログには、アプリケーションがデプロイされていることが示されていません。 –

答えて

0

あなたをデプロイするデフォルトでは、Tomcatに1つのアプリケーションしかデプロイされていない場合、コンテキストルートは '/'になります。あなたは具体的には、/desi、あなたはあなたが

<context:component-scan base-package="com.theka.desi.Controllers" /> 

を使用しているSpring構成ファイルで​​

+0

申し訳ありません、「Tomcatにデプロイされています。 Tomcatに追加すると、Tomcat webappのディレクトリが "ROOT"と呼ばれない限り、アプリケーションフォルダの名前が使用されます( 'myapp'を使用した場合は' localhost:8080 \ myapp'となります) – ismoore999

0

を使用する必要がありますされていることを述べていない限り、それはコントローラが存在するパッケージ名ですか?いいえの場合は、実際のパッケージに変更します。

次にコントローラクラスに@Controllerという注釈を付ける必要があります。この場合、Springは要求されたURLをマップするのに必要な他の注釈を使用できません。http://localhost:8080/desi/

+0

パッケージファイルのパス私のコントローラクラスの@controllerにも言及しています。問題のクラスを更新しました。plzが見て、いくつかの解決策を提案します。 – nand

+0

どの春バージョンですか? –

+0

4.0.3.RELEASE nand