I have finished learning Spring Boot from a tutorialspoint, my second learning path is Hibernate. They have mentioned that I need to download Hibernate package and then set CLASSPATH for it in order for its proper working.
My question is, does Spring.io contains Hibernate packages already? Or do I need to download Hibernate and set CLASSPATH manually?
CodePudding user response:
You don't need to download anything by your own.
https://start.spring.io/ uses Maven or Gradle as build tool and this contains the dependency management that will download the packages for you.
When you build the application the Spring Boot plugin will create an executable JAR where all the dependencies are included.
CodePudding user response:
Add this dependency to Maven
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
or this one for Gradle
implementation ("org.springframework.boot:spring-boot-starter-data-jpa")
This dependency includes JPA API, JPA Implementation, JDBC, and other needed libraries.
You can of course exclude the Hibernate
dependency from the spring-boot-starter
and import the dependency yourself (your preferred version) as:
For Maven:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.6.0.Final</version>
</dependency>
For Gradle:
implementation ("org.springframework.boot:spring-boot-starter-data-jpa") {
exclude group: "org.hibernate", module: "hibernate-core"
}
implementation "org.hibernate:hibernate-core:5.6.0.Final"
Please note that in order to use a database you must provide the Database driver, for instance, the H2
in-memory database:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>