Using Spring Data REST
Spring Data REST (https://spring.io/projects/spring-data-rest) is part of the Spring Data project. It offers an easy and fast way to implement RESTful web services with Spring. To start using Spring Data REST, you have to add the following dependency to the pom.xml
file:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-rest</artifactId> </dependency>
By default, Spring Data REST finds all public repositories from the application and creates RESTful web services for your entities automatically. In our case, we have two repositories: CarRepository
and OwnerRepository
, therefore Spring Data REST creates RESTful web services automatically for those repositories.
You can define the endpoint of service in your application.properties
file as follows:
spring.data.rest.basePath=/api
Now, you can access the RESTful web service from the localhost:8080...