2013-09-21 2 views
0

스프링 mvc를 사용하여 편안한 서비스를 만들어보십시오.하지만 액세스 할 수는 없습니다. 읽은 톤수의 대답이 모두 옳은 것처럼 보이면 어쩌면 뭔가를 볼 수있을 것입니다.스프링 MVC 3.2.4 @RequestMapping이 작동하지 않습니다.

21.09.2013 10:50:33 org.springframework.web.servlet.DispatcherServlet noHandlerFound 
WARNING: No mapping found for HTTP request with URI [/rest/book] in DispatcherServlet with name 'mvc-dispatcher' 

web.xml을

<web-app 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_3_0.xsd" 
     version="3.0" metadata-complete="true"> 

    <servlet> 
     <servlet-name>mvc-dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextClass</param-name> 
      <param-value> 
       org.springframework.web.context.support.AnnotationConfigWebApplicationContext 
      </param-value> 
     </init-param> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value> 
       ru.expbrain.flib.config.RestConfig 
      </param-value> 
     </init-param> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>mvc-dispatcher</servlet-name> 
     <url-pattern>/rest/*</url-pattern> 
    </servlet-mapping> 

    <welcome-file-list> 
     <welcome-file>index.hmtl</welcome-file> 
    </welcome-file-list> 

</web-app> 

RestConfig.java

package ru.expbrain.flib.config; 

import org.springframework.context.annotation.ComponentScan; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.web.servlet.config.annotation.EnableWebMvc; 
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 

@Configuration 
@EnableWebMvc 
@ComponentScan(basePackages = {"ru.expbrain.flib.rest.controller"}) 
public class RestConfig extends WebMvcConfigurerAdapter { 

} 

BookController.java

package ru.expbrain.flib.rest.controller; 

import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.RequestParam; 
import org.springframework.web.bind.annotation.ResponseBody; 
import ru.expbrain.flib.rest.entity.Book; 

import java.util.concurrent.atomic.AtomicLong; 

@Controller 
public class BookController { 

    private final AtomicLong counter = new AtomicLong(); 

    @RequestMapping(value="/book", method = RequestMethod.GET) 
    public @ResponseBody Book greeting(@RequestParam(value="content", required=false, defaultValue="World") String name) { 
     return new Book(counter.incrementAndGet(), name); 
    } 
} 

봅니다 경로를 통해 콘텐츠를 위해, BTW 루트 컨텍스트 경로로 이동/

http://localhost:9080/rest/book 
+0

응용 프로그램을 시작할 때 로그를 확인하십시오. 자세한 내용은 디스패처 매핑을 참조하십시오. –

+0

'BookController'가 인스턴스화되고 있습니까? ('@ PostConstruct' 메서드를 사용하여 로그 메시지를 쓸 수 있습니다.) – chrylis

+0

매핑 프로세스에 대한 언급은 없지만 show mvc-dispatcher-servlet 초기화는 – ArchCC

답변

0

테스트를 위해 Sotirios Delimanolis에 감사드립니다.

캐싱에 문제가있었습니다 ... 어떻게 처리되는지는 설명 할 수 없습니다. 클리닝으로 복구하지 않았기 때문에 ...하지만 프로젝트 도움말을 다시 작성하면 모두 정상적으로 보입니다.

관련 문제