Spring Data Configuration


1.Create a spring boot project. Spring Initializer
For dependencies, select the following,
a. JPA
b. MySQL Driver
c. Web

<!-- spring data -->
<!-- spring web -->
<!-- mysql driver -->

Import your project to your favorite IDE. I am using Spring suite tool for this tutorial.

2. Add these configurations to your application.properties file.


Note: createDatabaseIfNotExist=true will create your database if it does not exist.  It’s for development only.

3. Create a database in your localhost called spring_data. I am using MySQL Workbench.

4. Create a User class

package com.lovemesomecoding.user;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Table(name = "user")
public class User implements Serializable {

	private static final long serialVersionUID = 1L;

	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id", nullable = false, updatable = false, unique = true)
	private Long id;

	@Column(name = "name")
	private String name;

	@Column(name = "email")
	private String email;

	@Column(name = "age")
	private int age;

	public User() {
		// TODO Auto-generated constructor stub

	public Long getId() {
		return id;

	public void setId(Long id) {
		this.id = id;

	public String getName() {
		return name;

	public void setName(String name) {
		this.name = name;

	public String getEmail() {
		return email;

	public void setEmail(String email) {
		this.email = email;

	public int getAge() {
		return age;

	public void setAge(int age) {
		this.age = age;

5. Create a UserRepository interface that implements JpaRepository

package com.lovemesomecoding.user;

import org.springframework.data.jpa.repository.JpaRepository;

public interface UserRepository extends JpaRepository<User, Long> {


That is all the configuration we have to do. As you can see, spring boot makes it easy for us to get up and running. There is not a lot of configurations to do before writing code. It’s one of the reasons why I love spring boot.

Checkout Source Code On Github


Subscribe To Our Newsletter
You will receive our latest post and tutorial.
Thank you for subscribing!


Leave a Reply

Your email address will not be published. Required fields are marked *