1

I want to make a simple java application and I want to use CRUDREPOSITORY and my own repository. I have this:

@RestController
@Transactional
@ExposesResourceFor(Person.class)
@RequestMapping("/prueba")
public class PersonController  {

    @RequestMapping(value="/prueba", method=RequestMethod.GET)
    public String person(@RequestParam(value="id", defaultValue="1") int id) {      
    return "hola"+id;
}

}

this:

@RepositoryRestResource
public interface IClientRepository extends CrudRepository<Client, Long> {
}

The problem is that the CRUD works well, but I can´t call my localhost:8080/prueba/prueba because it gives a 404 error. I have try all and I cant access it, please help me!!

5
  • How are you running this? Commented Sep 6, 2016 at 20:05
  • As Spring Boot App :) Commented Sep 6, 2016 at 20:27
  • When you start up your spring application it will list off the request mappings that it found from your controllers and any auto configured stuff (i.e. @RepositoryRestResource). Is there a mapping there for /prueba/prueba? Commented Sep 7, 2016 at 6:07
  • what happens for something like http://<server>/<app>/prueba/prueba?id=1 Commented Sep 7, 2016 at 6:30
  • I think it was a problem about Spring-boot MVC dependency, suddenly it works when I added that dependency, I don´t know very well why this happened but if someone have the same problem, my solution was --> Add the MVC dependency and clean the project. P.D: the mapping for /prueba/prueba does not appear in the list of the start, but now, it works Commented Sep 7, 2016 at 7:08

1 Answer 1

1

By default, Spring Data REST serves up REST resources at the root URI, "/". There are multiple ways to change the base path.

With Spring Boot 1.2+, add below to application.properties:

spring.data.rest.basePath=/api

In your case: spring.data.rest.basePath=/prueba/prueba , assuming there is no override for server.contextPath in application.properties

Reference: http://docs.spring.io/spring-data/rest/docs/current/reference/html/

Sign up to request clarification or add additional context in comments.

2 Comments

The original question says that the CRUD works well (exposing the REST resource). The problem is the additional REST endpoint is not returning a value at /prueba/prueba which is defined in the annotations of the controller class and method.
The question did not say that whether CRUD works well on root path or the intended one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.