Q:

@RestController @GetMapping No adapter for handler issue

Learning Spring Rest, had some doubt on below:
@RestController
public class TestController {

    @Autowired
    private TestService testService;

    @GetMapping("/test")    
    public int testTransaction(){
        return 10;
    }
}

Above snippet worked very well, and returned response 10.
@RestController("/test")
public class TestController {

    @Autowired
    private TestService testService;

    @GetMapping 
    public int testTransaction(){
        return 10;
    }
}

For above snippet, getting me an error as below:
 threw exception No adapter for handler The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler with root cause

Any idea? what could be the reason..? I am thinking both should work, but above one is not working...

A:

In your second code piece you didn't specify request mapping for your controller.
This should be done in @RequestMapping not in @RestController.
This should work:
@RequestMapping("/test")
@RestController
public class TestController {

    @Autowired
    private TestService testService;

    @GetMapping 
    public int testTransaction(){
        return 10;
    }
}

Your first code piece works because you specified request mapping on a method level - @GetMapping("/test") 

