2014-07-27 16 views
6

cố gắng thực hiện một số chương trình ví dụ mùa xuân - liên tục nhận được lỗi - điều đó xảy ra là bộ điều khiển của tôi không thể xử lý/yêu cầu xin chào. Đây là thông tin gỡ lỗi từ log4j.RequestMappingHandlerMapping.getHandlerInternal: 230 - Không tìm thấy phương thức xử lý cho

13:50:58,502 {TRACE} DispatcherServlet.initContextHolders:1018 - Bound request context to thread: [email protected] 
    13:50:58,503 {DEBUG} DispatcherServlet.doService:823 - DispatcherServlet with name 'springtest' processing GET request for [/springtest_2/hello] 
    13:50:58,504 {TRACE} DispatcherServlet.getHandler:1088 - Testing handler map   
[org.springframework[email protected]7bab2c3] in DispatcherServlet with name 'springtest' 
    13:50:58,504 {DEBUG} RequestMappingHandlerMapping.getHandlerInternal:220 - Looking   
    up handler method for path /hello 
    13:50:58,504 {DEBUG} RequestMappingHandlerMapping.getHandlerInternal:230 - Did not find handler method for [/hello] 
    13:50:58,504 {TRACE} DispatcherServlet.getHandler:1088 - Testing handler map [or[email protected]722e242b] in   DispatcherServlet with name 'springtest' 
    13:50:58,505 {TRACE} BeanNameUrlHandlerMapping.getHandlerInternal:127 - No handler mapping found for [/hello] 
    13:50:58,505 {WARN} PageNotFound.noHandlerFound:1108 - No mapping found for HTTP request with URI [/springtest_2/hello] in DispatcherServlet with name 'springtest' 
    13:50:58,505 {TRACE} DispatcherServlet.resetContextHolders:1028 - Cleared thread-bound request context: [email protected] 
    13:50:58,505 {DEBUG} DispatcherServlet.processRequest:966 - Successfully completed request 
    13:50:58,506 {TRACE} XmlWebApplicationContext.publishEvent:332 - Publishing event in WebApplicationContext for namespace 'springtest-servlet': ServletRequestHandledEvent: url=[/springtest_2/hello]; client=[0:0:0:0:0:0:0:1]; method=[GET]; servlet=[springtest]; session=[null]; user=[null]; time=[9ms]; status=[OK] 

web.xml từ dự án của tôi.

<?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_3_0.xsd" 
id="WebApp_ID" version="3.0"> 
<display-name>Spring3-Hibernate DEMO</display-name> 

<listener> 
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> 
</listener> 

<context-param> 
    <param-name>log4jConfigLocation</param-name> 
    <param-value>/WEB-INF/log4j.properties</param-value> 
</context-param> 

<!-- The front controller of this Spring Web application, responsible for handling all application requests --> 
<servlet> 
    <servlet-name>springtest</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/springtest-servlet.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<!-- Map all requests to the DispatcherServlet for handling --> 
<servlet-mapping> 
    <servlet-name>springtest</servlet-name> 
    <url-pattern>/*</url-pattern> 
</servlet-mapping> 

</web-app> 

mùa xuân-test-servlet.xml - tập phối từ dự án của tôi

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:mvc="http://www.springframework.org/schema/mvc" 
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-3.0.xsd 
http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" > 

<mvc:annotation-driven /> 

<context:component-scan base-package="com.denmroot.controller"/> 

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

ControllerMain.java - từ dự án của tôi

package com.denmroot.controller; 

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

@Controller 
public class ControllerMain { 

@RequestMapping(value = "/hello", method = RequestMethod.GET) 
    public String helloworld (ModelMap model) { 
    model.addAttribute("message", "Hello World !!! Spring Output"); 
    return "hello";  
} 

} 
+0

thể trùng lặp của [Mùa xuân gọi lập bản đồ bộ điều khiển sai] (http://stackoverflow.com/questions/11861609/spring-invokes-wrong- ánh xạ điều khiển) – Jens

+0

Thay đổi mẫu Url thành \ không giải quyết vấn đề. springtest / DENMROOT

+0

Không hiểu ý bạn là sao chép của Spring - đọc liên kết, không thấy gì liên quan đến câu hỏi của tôi. – DENMROOT

Trả lời

0

Trên thực tế nhật ký nói tất cả mọi thứ:

  • Hoặc thay đổi ur của bạn l từ khách hàng để chỉ /hello đường

  • Hoặc bản đồ của bạn @Controller với:

    @Controller 
    @RequestMapping("/springtest_2") 
    public class ControllerMain { 
    
+0

Cảm ơn câu trả lời của bạn nhưng bộ điều khiển ánh xạ với ("/ springtest_2") không giúp bạn nhận được lỗi tương tự. – DENMROOT

+0

Ngữ cảnh của bạn có thực sự định cấu hình ánh xạ cho lớp được chú thích của bạn không?Là 'ControllerMain' của bạn trong trình nạp lớp ứng dụng web? –

+0

Ý của bạn là - Có Controller nằm trong vùng chứa com.denmroot.controller. – DENMROOT

0

@Controller

chú thích là mất tích cho lớp điều khiển của bạn.

0

Đối với tôi, tôi đã có một lỗi đánh máy trong file config mùa xuân mà chỉ vào gói:

Là:

<context:component-scan base-package="com.something.web.controlers" /> 

cố định với đúng chính tả:

<context:component-scan base-package="com.something.web.controllers" /> 
1

ControllerMain.java yêu cầu câu lệnh @RequestMapping ("/") sau @Controller.

Thay đổi:

@Controller 
public class ControllerMain { 

@RequestMapping(value = "/hello", method = RequestMethod.GET) 
.... 
.... 

Để:

@Controller 
@RequestMapping("/") 
public class ControllerMain { 

@RequestMapping(value = "/hello", method = RequestMethod.GET) 
.... 
.... 
.... 
Các vấn đề liên quan