Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@PathVariable is simply not working

Tags:

spring-boot

In my Spring Boot application I added an API

@RequestMapping(value = "/abc/{input}", method=RequestMethod.GET)
@ResponseBody
public WhitelistStatus getInput(@PathVariable("input") String input);

I deployed this application and made a call - http://localhost:8080/abc/123

I put a debug point in my code and the path variable input which should be "123" always comes as null.

I've been trying to resolve this for sometime now. There is no ambiguity in the URL as this is the only API. Can someone please tell me what I'm doing wrong here?

like image 249
user3740951 Avatar asked Dec 05 '25 15:12

user3740951


2 Answers

Well I found the issue. I have to add @PathVariable annotation in the implementation method as well. I only had it in the interface first And it works!

like image 146
user3740951 Avatar answered Dec 07 '25 14:12

user3740951


I had same issue,but now its solved.
Add @PathVariable at class level as well because PathVariable is not inherited from interface thats why it is not working.

Add(at implementing class level) :-
public WhitelistStatus getInput(@PathVariable("input") String input){

// implementation code here

}

like image 20
NeeruKSingh Avatar answered Dec 07 '25 15:12

NeeruKSingh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!