2013-07-19 4 views
0

Я следую this tutorial и побежал в следующую ошибку:«Привет мир» ошибка учебник

> Jul 19, 2013 2:18:14 PM 
> org.springframework.web.servlet.DispatcherServlet noHandlerFound 
> WARNING: No mapping found for HTTP request with URI 
> [/Spring3MVC/hello.html] in DispatcherServlet with name 'spring' 

Я могу открыть первый jsp файл (index.jsp), но когда я нажимаю на «поздороваться» он показывает 404 мне. Я попробовал методы, предложенные в комментариях к учебнику, но они не сработали.

Единственное место, где я отклонился от учебника, это то, что я использую Tomcat 7 вместо 6. Все остальное выглядит одинаково с использованием Eclipse. Мой код такой же, как в учебнике, поэтому не нужно вставлять его прямо сейчас. :)

hello.jsp путь к файлу:

Spring3MVC\WebContent\WEB-INF\jsp\hello.jsp 

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" 
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    id="WebApp_ID" version="2.5"> 
    <display-name>Spring3MVC</display-name> 
    <welcome-file-list> 
     <welcome-file>index.jsp</welcome-file> 
    </welcome-file-list> 

    <servlet> 
     <servlet-name>spring</servlet-name> 
     <servlet-class> 
      org.springframework.web.servlet.DispatcherServlet 
     </servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>spring</servlet-name> 
     <url-pattern>*.html</url-pattern> 
    </servlet-mapping> 
</web-app> 

весна-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:p="http://www.springframework.org/schema/p" 
    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-3.0.xsd 

http://www.springframework.org/schema/context 


http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

    <context:component-scan 
     base-package="net.viralpatel.spring3.controller" /> 

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

Controller.java

package net.viralpatel.spring3.controller; 

import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.servlet.ModelAndView; 

@Controller 
public class HelloWorldController { 

    @RequestMapping("/hello.html") 
    public ModelAndView helloWorld() { 

     String message = "Hello World, Spring 3.0!"; 
     return new ModelAndView("hello", "message", message); 
    } 
} 

Tomcatlog:

Jul 19, 2013 3:25:00 PM org.apache.catalina.core.AprLifecycleListener init 
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\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Python27;C:\cloudbees-sdk-1.5.0;C:\Python27\Scripts;C:\eclipse\SDK\adt-bundle-windows-x86_64-20130522\sdk\platform-tools;C:\tomcat 7.0.12;C:\Windows\System32;C:\Program Files (x86)\Google\google_appengine\;. 
Jul 19, 2013 3:25:00 PM org.apache.tomcat.util.digester.SetPropertiesRule begin 
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Spring3MVC' did not find a matching property. 
Jul 19, 2013 3:25:00 PM org.apache.coyote.AbstractProtocol init 
INFO: Initializing ProtocolHandler ["http-bio-8080"] 
Jul 19, 2013 3:25:00 PM org.apache.coyote.AbstractProtocol init 
INFO: Initializing ProtocolHandler ["ajp-bio-8009"] 
Jul 19, 2013 3:25:00 PM org.apache.catalina.startup.Catalina load 
INFO: Initialization processed in 834 ms 
Jul 19, 2013 3:25:00 PM org.apache.catalina.core.StandardService startInternal 
INFO: Starting service Catalina 
Jul 19, 2013 3:25:00 PM org.apache.catalina.core.StandardEngine startInternal 
INFO: Starting Servlet Engine: Apache Tomcat/7.0.42 
Jul 19, 2013 3:25:02 PM org.apache.catalina.core.ApplicationContext log 
INFO: Initializing Spring FrameworkServlet 'spring' 
Jul 19, 2013 3:25:02 PM org.springframework.web.servlet.FrameworkServlet initServletBean 
INFO: FrameworkServlet 'spring': initialization started 
Jul 19, 2013 3:25:02 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh 
INFO: Refreshing WebApplicationContext for namespace 'spring-servlet': startup date [Fri Jul 19 15:25:02 EEST 2013]; root of context hierarchy 
Jul 19, 2013 3:25:02 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-servlet.xml] 
Jul 19, 2013 3:25:02 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons 
INFO: Pre-instantiating singletons in org.s[email protected]44dc42ab: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,viewResolver]; root of factory hierarchy 
Jul 19, 2013 3:25:02 PM org.springframework.web.servlet.FrameworkServlet initServletBean 
INFO: FrameworkServlet 'spring': initialization completed in 628 ms 
Jul 19, 2013 3:25:02 PM org.apache.coyote.AbstractProtocol start 
INFO: Starting ProtocolHandler ["http-bio-8080"] 
Jul 19, 2013 3:25:02 PM org.apache.coyote.AbstractProtocol start 
INFO: Starting ProtocolHandler ["ajp-bio-8009"] 
Jul 19, 2013 3:25:02 PM org.apache.catalina.startup.Catalina start 
INFO: Server startup in 1982 ms 
Jul 19, 2013 3:25:05 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound 
WARNING: No mapping found for HTTP request with URI [/Spring3MVC/hello.html] in DispatcherServlet with name 'spring' 
Jul 19, 2013 3:35:54 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound 
WARNING: No mapping found for HTTP request with URI [/Spring3MVC/hello.html] in DispatcherServlet with name 'spring' 

(PS! возможно, вы также можете указать мне на рабочий учебник)

+0

изменить его '@RequestMapping ("/hello ")' to '@RequestMapping ("/hello.html ")' from contoller. –

+0

ничего не изменил –

+0

вы можете разместить свой код? –

ответ

2

Ваш файл имеет имя sprint-servlet.xml? Может, в этом и проблема.

Как указал Сотириос Делиманолис, он должен быть назван в честь тега по умолчанию.

Название файла должно быть spring-servlet.xml.

Примером весеннего приложения является here.

Официальный учебник по весне - here.

+0

Предполагается, что он по умолчанию называется тегом ' '. –

+0

@SotiriosDelimanolis посмотреть на вопрос. Ответчик написал «файл sprint-servlet.xml:» –

+1

Правильно скажите ему, как его исправить. Я не исправлял тебя. –

Смежные вопросы