2017-07-14 149 views
0

我有以下控制器:@RepositoryRestController不承認

@RepositoryRestController 
public class TestController { 

    @RequestMapping(value = "/testables", method = RequestMethod.GET) 
    public String get(){ 

     return "testin it"; 

    } 

} 

而且它不是由Spring回升。當我點擊/apiroot/testables地址時,我得到404。如果我將其更改爲@RestController並添加api root來請求映射值,那麼它就可以工作。另外,如果我將映射更改爲指向"/orders/testables",則它的工作方式爲@RepositoryRestController。我也有在同一個包下面控制器的正常工作:

@RepositoryRestController 
public class SendEmailController { 

    @Autowired 
    private MessageSource messageSource; 

    @Autowired 
    private JavaMailSender javaMailSender; 

    @Autowired 
    private OrderRepository orderRepository; 

    @RequestMapping(value = "/orders/{id}/sendOrderEmailToSupplier") 
    public void sendOrderEmailToSupplier(@PathVariable("id") Long id, WebRequest request) throws MessagingException {... 
+0

你是如何設置[basePath](https://docs.spring.io/spring-data/rest/docs/current/reference/html/#_changing_the_base_uri)的? – Cepr0

+0

在'application-default.yml'中,'spring:data:rest:basePath:/ basepath' – aycanadal

+0

很奇怪。在我的測試項目中,所有工作都按預期工使用1.5.4或1.4.3 Spring Boot。 – Cepr0

回答

1

@RepositoryRestController處理基本路徑只爲它管理資源。在其他情況下,路徑不應包含「基礎」。

如果要在basePath之下構建自定義操作,則可以使用@BasePathAwareController