Not sure that this is the right way to do but I think it's ok as a workaround. You can implement a setter method where you can add the @PathVariable annotation. If you apply this approach it would make sens to have a dedicated request object.
public class UserDto {
private Long id;
private String name;
public void setId(@PathVariable Long Id) {
this.id = id;
}
}
If there is a better solution I did not find please link it.