Spring Framework - Spring Boot - Spring Boot- Hibernate-REST Integration
Start
Add REST support
Add spring-boot-starter-web dependency to pom.xml. You may skip version tag, if you are using spring-boot-starter-parent as the parent of your pom.xml (reference(opens new window)).
Add REST controller to desired package, for example to **com.example.myproject.web.rest** ([reference](http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#getting-started-first-application-code)):
Start Spring Boot application ([reference](http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#getting-started-first-application-run)).
Your controller is accessible at the address **[http://localhost:8080/api/version](http://localhost:8080/api/version)**.
Add Hibernate support
Add spring-boot-starter-data-jpa dependency to pom.xml. You may skip version tag, if you are using spring-boot-starter-parent as the parent of your pom.xml. The dependency below brings Hibernate and everything related to JPA to your project (reference(opens new window)).
Add database driver to **pom.xml**. This one below is for H2 database ([reference](http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-embedded-database-support)).
Enable debug logging for Hibernate in **application.properties**
logging.level.org.hibernate.SQL = debug
or in application.yml
logging:
level:
org.hibernate.SQL: debug
Add entity class to desired package under **${project.home}/src/main/java/**, for example under **com.example.myproject.domain** ([reference](http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-entity-classes)):
Add **import.sql** to **${project.home}/src/main/resources/**. Put **INSERT** statements into the file. This file will be used for database schema population on each start of the app ([reference](http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-initialize-a-database-using-hibernate)):
insert into city(name) values ('Brisbane');
insert into city(name) values ('Melbourne');
Add Repository class to desired package under **${project.home}/src/main/java/**, for example under **com.example.myproject.service** ([reference](http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-spring-data-jpa-repositories)):