My interface:
package com.demo.dependency;
@RestController
@RequestMapping(value = "#{'${api.baseUrl}'}")
public interface BaseController<Response> {
@PostMapping(value = "#{'${api.interface}'}")
@ResponseBody
public Response process(@RequestBody @Valid Request request) throws Exception;
}
Implementation:
package com.demo.application;
public class BarController implements BaseController<BarResponse> {
@Override
public BarResponse process(Request request) throws Exception {
// do something
}
}
I'm new to Spring Boot. I wonder whether these annotations can work properly in implementation class:
- @RestController and @RequestMapping on interface class
- @PostMapping and @ResponseBody on interface method
- @RequestBody and @Valid on method parameters
#{'${api.baseUrl}'}and#{'${api.interface}'}to read configure fromapplication.properties
My spring boot version is 2.2.6.
It seems that my SpringApplication from package com.demo.application failed to auto scan BarController. However, this answer says that "the annotation should apply to all subclasses", including @Service. Is anything wrong with my code?
Thanks in advance.