We will make a simple User entity with some fields with which we will be able to demonstrate simple JPA queries: package We will have a look at this console once we run our project. This property of Spring Boot enables the Web UI for our in-memory database which is accessible via the following link: Note that this URL is reachable only when our application is in running mode. I am going to add a single property to the application.properties file, which is to enable the H2 console: # Enabling H2 Console The best thing about using an in-memory database is that we don’t have to do any configuration at all. The project code is organized into multiple packages so that the principle of separation of concern is followed and code remains modular. Below are the dependencies we will need for now: īelow is an example of a project structure. To implement our project with Spring Boot and use H2 as our in-memory database, we will use Maven to manage dependencies. Use any IDE to open the downloaded Maven-based project. Though this tool helps us to add the above dependencies, below is the source code of pom.xml file from which you can copy these dependencies and add them to your project manually. When creating a new project with the Spring Initializr, we used the following dependencies: Using this tool, we can quickly provide a list of Dependencies we need and download the bootstrapped application: To quickly set up our project, we will use a tool called Spring Initializr. In this lesson, we will see what we can do with an in-memory database when it is integrated with a Spring Boot application. For running unit test cases, you want to use temporary data instead of actual data in your DB.įor use-cases like the above, in-memory databases are quite evident in usage due to their quick setup and minimal configuration needed at the application side.A quick POC (Proof of Concept) where you don’t want to invest time in setting up a database and constructing a schema for the app.H2 is a pretty fast database and can be used for many purposes like: It is very much lightweight and its JAR file is only 1.5MB in size.Īlthough H2 is an in-memory database, it means that data will be wiped out of the memory as soon as the application is stopped. H2 database is an open-source database written in Java programming language, which supports querying data in standard SQL. Note: If your project uses Spring Security, then following this tutorial, Add H2 Database to Spring Boot Project with Spring Security. You will learn how an in-memory database like H2 can be used to develop a Spring boot application without the overhead of doing DB configuration on your machine and without specifying any config details in the app. In this tutorial, we will create a Spring Boot application which demonstrates how we can add and use the H2 in-memory database in our application. User Registration, Log in, Log out – Video Tutorials.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |