I have currently have an application that is using Spring Boot and Spring Data. I have my domain objects that were reverse engineered from my database and I have several repositories (classes). Each repository is an interface that extends the CrudRepository.
import org.springframework.data.repository.CrudRepository
interface MyDomainClassRepository extends CrudRepository<MyDomainClass, Integer> {
private MyDomainClass findByName(String name);
}
At this point I would create a service that would implement these items. The service would then be called by a REST controller.
I wanted to be able to have Spring create my REST API automatically if possible and I found the Spring Data REST project. I found this http://spring.io/guides/gs/accessing-data-rest/ and I can follow that guide, but I don't understand what is enabling the "REST APIs" to be created "automatically". I could understand it if the @RepositoryRestResource annotation caused the API to be created but in that guide it explicitly says
RepositoryRestResource is not required for a repository to be exported. It is only used to change the export details, such as using /people instead of the default value of /persons.
Does including in my POM file and rebuilding "automatically" allow Spring Data to create the REST endpoints?
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
What keyword, section am I missing that makes it so the API endpoint is created automatically?
endpoint
in your context but if you'd like to have an endpoint for viewing, say,users
you would have to create aRequestMapping
for it in your controller. There is also aSpring Actuator
service that has Spring defined endpoints. See this. - px06@RequestMapping
in my controller. But I don't see what the difference in doing it through@RequestMapping
or@RepositoryRestResource(collectionResourceRel
= "people", path = "people")? For example where did "localhost:8080/people/search" come from? That seems to be automatically generated. I was under the impression that the Spring Data REST would automatically create my DELETE, POST for me instead of me having to do it. My problem is, based on the example, I don't see how it is being told to do that. - Kevin Vasko