This tutorial covers how to use MapStruct library to map automatically your Data Transfer Objects with your repository data. We will use the JPA layer of a Spring Boot application to access your data.
Data Access
This section will teach you how to add database access to the Spring Boot applications using the following elements:
- A running database, whether initiated by/embedded within your application or
simply accessible to your application - Database drivers enabling programmatic access, usually provided by the database vendor
- A Spring Data module for accessing the target database.
How to debug SQL statements in Spring Boot applications
Spring boot auto-configuration does not require a dedicated logging configuration file. So, in order to debug your SQL Statements in Spring Boot applications, by default can use the following settings in your application.properties file: logging.level.org.hibernate.SQL=DEBUG logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE When this configuration is added, you will be able to see: 1) Each SQL Statement executed 2) The timing … Read more
GraphQL tutorial for Spring Boot developers
GraphQL is a specialized query language which gives us an alternative a more flexible approach to managing data in our application than restful design. In this tutorial we will learn how to use GraphQL with a Spring Boot application.
How to add initial data in Spring Boot JPA applications
In order to have some data inserted at application start up, all you have to do is creating a data.sql file in your src/main/resources folder and it will be automatically executed on startup. Within this file, place your SQL INSERT Statements: INSERT into CUSTOMER(id,name,surname) VALUES (1,’aaaa’,’bbbbbb’) INSERT into CUSTOMER(id,name,surname) VALUES (2,’cccc’,’dddddd’) On the other hand, … Read more
How to get your DB Tables automatically created with Spring Boot
A common requirement when you are developing and testing your application is to use create and drop your database schema at start up. Let’s learn how to do that in a simple Spring Boot application.
How to define a Mock Repository in Spring Boot
The key to define a Mock Repository is the @Repository annotation. @Repository is a Spring annotation that indicates that the decorated class is a repository.
Create a JPA Application using Groovy and Spring Boot
You can create a Spring Boot application using Groovy either from the IDE or using the online Spring Boot application generator http://start.spring.io and selecting Groovy as the language. You’ll now see how to develop a simple Spring Boot web application using Groovy, Spring Data JPA, and Thymeleaf. Add the Web, Thymeleaf, JPA, and H2 starters … Read more
How to connect to H2 Console in Spring Boot
In order to enable H2 In-Memory Database in Spring Boot applications you have to include the “h2” dependency in your initializer. For example: spring init -dweb,jpa,h2 demo-h2 The H2 Database provides a web interface called H2 Console to see the data. You can enable the h2 console in the src/main/resources/application.properties # Enabling H2 Console spring.h2.console.enabled=true … Read more
Configuring SpringBoot to use MySQL
In this tutorial we will learn how to create a basic application using Spring Boot CLI and MySQL as database. We will then import the application into an IDE to create a sample application which stores some data which is later retrieved by the SpringApplication class.