简体   繁体   中英

Why @GetMapping don't work, when @RequestMapping working properly?

I deploy my REST application on Weblogic (i don't use web.xml, version of Spring is 5.1.0). If method annotated like this all ok

@RequestMapping(value = "/test", method = RequestMethod.GET)
public Cat searchCats(@RequestParam(name = "Name") String Name){
   //some code 
   return new Cat();
}

during deploy i see logs from weblogic Mapped {[/logs],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}

but if i annotated like this

@GetMapping("/logs")
 public Cat searchCats(@RequestParam(name = "Name") String Name){
    //some code 
    return new Cat();
 }

There is no correct mapping in ServletContex during the deploy Mapped {[],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}

update annotation @GetMapping(path="/logs")

@GetMapping(path="/logs")
 public Cat searchCats(@RequestParam(name = "Name") String Name){
    //some code 
    return new Cat();
 }

In @GetMapping version, you use a RequestParam, but not provide it in path. Try with:

@GetMapping(path = "/logs/${Name}")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM