Thursday, 24 March 2016

Creating a Simple Spring Data Project

To create a simple Spring Data Project in Spring Tool Set we can use a Spring starter project.

In STS create a new Spring Starter Project.

In the Maven POM file use:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>


        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>

This will get you all the Spring Data dependencies,  and if you want to try out with and in memory database H2 will also be fetched.

Then in the project properties file in the resource folder, put the following configuration.

spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = update
logging-level = DEBUG
spring.datasource.url = jdbc:h2:~/test
spring.datasource.username = sa
spring.datasource.password =

You will NOT require last three entries if you do not have a stanalone verioin of H2 database.

Thats it you now have a Spring Data Project with H2 database up and Running.

No comments:

Post a Comment