Posts

Showing posts from August, 2020

Spring Boot Dependency Management - spring-boot-starter-parent

All spring boot application uses the spring-boot-starter-parent as the parent in pom.xml like below. It is a special project, the provides default configuration for our application (Java version and other properties),   complete dependency tree to quickly build our spring boot project and default plugin configurations (maven-failsafe-plugin, maven-jar-plugin etc..). <parent> <groupId> org.springframework.boot </groupId> <artifactId> spring-boot-starter-parent </artifactId> <version> 2.3.3.RELEASE </version> <relativePath/> <!-- lookup parent from repository --> </parent> Once we declared the starter parent in our project, we can just pull any dependencies from the parent by just declaring it our dependencies tag, and also we don't need to define versions of the dependencies. Maven will download jar files based on the version defined for starter parent in the parent tag. If you want different dependency vers...

Spring Rest Repositories - @RepositoryRestResource

Image
If you are so lazy to write lot of boilerplate code to create simple rest end points to your repository entity, the good news for you. Using Spring Boot and Spring Data Rest, we can develop a fully restful endpoints in a few steps with less code. Say you have an entity named Product, you will be creating a repository interface which extends JpaRepsitory. Your interface will be like this. We automatically get a bunch of database repository out of box methods like findAll, findOne, etc.. public interface ProductRepository extends JpaRepository < Product , Long > Previously, we used to create a Controller and create end points for the entity, to support the repository methods. But now the magic happens here in the repository interface.  Just by adding the @RepositoryRestResource annotation at the top of the interface provides us all the rest endpoints. By default, spring will use the pluralized entity name for the endpoint.  Now just start the application and go to http://...