2016-04-21 121 views
0

我创建了所有@Entity一个@RestController对象的REST URL被设置正确使用application.peropertiesspring.data.rest.base-path变量设定为/api但对于@RequestMapping("someEndpoint")它没有使用变量。@Controller不再使用spring.data.rest.base路径变量REST URL为@RequestMapping

对于@Entity类用户的REST端点位于:

`http://localhost:8081/api/users' 

但是当我试图访问someEndpoint

'http://localhost:8081/api/someEndpoint' 

我得到的回应:

回复状态

HTTP/1.1 404 Not Found 

身体

"timestamp":1461267817272,"status":404,"error":"Not Found","message":"No message available","path":"/api/someEndpoint"} 

取而代之的是REST服务的端点位于

'http://localhost:8081/someEndpoint' 

响应:

HTTP/1.1 200 OK 

Controller类

@RestController 
public class HomeController { 

    @RequestMapping(value = "/") 
    public String index() { 
     return "index"; 
    } 

    @RequestMapping("someEndpoint") 
    public Stuff runSomething(
      @RequestParam(value = "id", required = true) String id) 

我在配置中缺少什么?

谢谢

回答

3

spring.data.rest.base-path的Spring数据REST,它通过REST与HATEOAS不是Spring上下文暴露库到外部。

你想要的是server.context-path春天MVC的东西。

检查here为完整的属性。

+0

谢谢。我有一个Spring Data REST对象的混合体,所以我将同时使用这两个对象。 – ALM