实际上,正如@ dino-tw所提到的,您正在尝试实例化具有未定义依赖关系的抽象类.您绝对可以拥有一个抽象的控制器类,甚至可以定义将由所有子类继承的请求处理方法.试试这个:
public abstract class AbstractRestController{ private final JpaRepository repository; public AbstractRestController(JpaRepository repository){ this.repository = repository; } @RequestMapping(value = "/{id}", method = RequestMethod.GET) public ResponseEntity > getOne(@PathVariable ID id) { T restObj = repository.findOne(id); JsonResponseBody response = new JsonResponseBody<>(ResponseStatus.SUCCESS, restObj); return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON_UTF8).body(response); } protected JpaRepository getRepository(){ return repository; } } @RestController @RequestMapping(value = "/api/v1/customer") public class CustomerController extends AbstractRestController { @Autowired public CustomerController(CustomerRepository repository){ super(repository); } }