2014-07-11 89 views
-2
@Controller(value = "/rest")  
public class AppRestController { 

    @RequestMapping(value= "/upload-metadata", method = RequestMethod.POST) 
    public @ResponseBody Boolean uploadMetadata(@RequestBody MetadataForm metadataForm){ 
     Logger.info("uploading metadata : {0}", metadataForm.getTitle()); 
     return true; 
    }; 

和我的日誌消息只顯示:控制器URL進行註冊,但不是方法,彈簧MVC

Jul 11, 2014 1:54:09 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler 
INFO: Mapped URL path [/rest] onto handler '/rest' 
Jul 11, 2014 1:54:10 PM org.springframework.web.servlet.FrameworkServlet initServletBean 
INFO: FrameworkServlet 'mvc-dispatcher': initialization completed in 864 ms 

的方法實際requestmappings不顯示?我得到他們的404:

Jul 11, 2014 1:54:43 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound 
WARNING: No mapping found for HTTP request with URI [/rest/upload-metadata] in DispatcherServlet with name 'mvc-dispatcher' 
+0

移動值= 「/休息」 以階級基礎 –

+0

@HankLapidez上RequestMapping吧?我所表現出來的方式很好,不是嗎?在3.2中工作。這是4 btw。 – NimChimpsky

+0

我從來沒有使用控制器(值)。總是另一種方法,沒有問題。該來源表示該值是針對組件名稱的。 http://grepcode.com/file/repo1.maven.org/maven2/org.springframework/spring-context/4.0.4.RELEASE/org/springframework/stereotype/Controller.java#Controller –

回答

1

這應該工作。該方法應該在myapp上調用/ rest/upload-metadata

@Controller 
@RequestMapping(value = "/rest")  
public class AppRestController { 

    @RequestMapping(value= "/upload-metadata", method = RequestMethod.POST) 
    public @ResponseBody Boolean uploadMetadata(@RequestBody MetadataForm metadataForm){ 
     Logger.info("uploading metadata : {0}", metadataForm.getTitle()); 
     return true; 
    }; 
+0

但日誌messaghe顯示其餘已註冊? – NimChimpsky

0

雖然您沒有給出完整的控制器,請參考@RequestMapping和@Controller的spring文檔,你的映射應該是這樣的。

@Controller 
@RequestMapping("/rest")  
public class AppRestController { 
private static final Logger log = LoggerFactory.getLogger(AppRestController.class); 

@RequestMapping(value = "/upload-metadata", method = RequestMethod.POST) 
@ResponseBody 
public Boolean uploadMetadata(@RequestBody MetadataForm metadataForm) { 
    log.info("uploading metadata : {0}", metadataForm.getTitle()); 
    return true; 
} 

}

所有最優秀的