ALM
ALM

Reputation: 2705

@Controller no longer using spring.data.rest.base-path variable for REST URL for @RequestMapping

I created a @RestController for all @Entity objects the REST URL is being set correctly using spring.data.rest.base-path variable set in application.peroperties as /api but for a @RequestMapping("someEndpoint") it is not using the variable.

Example

For @Entity class User the REST endpoint is located at:

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

But when I try to access someEndpoint:

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

I get a response of:

Response Status

HTTP/1.1 404 Not Found

Body

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

Instead the endpoint of the REST service is located at

'http://localhost:8081/someEndpoint'

Response:

HTTP/1.1 200 OK

Controller class

@RestController
public class HomeController {

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

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

What am I missing in my configuration?

Thank you

Upvotes: 1

Views: 2789

Answers (1)

wener
wener

Reputation: 7750

spring.data.rest.base-path is for Spring Data REST, which expose Repository to outside by REST with HATEOAS not for spring context.

What you want is server.context-path for Spring MVC stuff.

Check here for full properties.

Upvotes: 6

Related Questions