AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Postgres app1/6/2024 ![]() If you are running on Linux or Mac, you must change to 127.0.0.1 as the Docker Host is your machine. The IP 192.168.99.100 is the assigned by Docker to the host machine in Windows or MacOS machines. Each RDBMS (like PostgreSQL, MySQL, Oracle, etc.) has its format. Here’s a quick explanation of each property: Update src/main/resources/application.properties to define your database connection properties: =jdbc:postgresql://192.168.99.100:5432/coursedb Previously, it was possible to get runtime errors since XML and your code was not linked. The feature is a nice evolution from the older XML-based configuration Spring used to have. This means if something becomes inconsistent with your configuration, it will show compilation errors. n(PostgresqlApplication.class, args) Ĭonfiguration annotations in Spring allow you to set up your application using type-safe code. ![]() First, change your main class (probably .PostgresqlApplication) and add the annotation to it, like this: package You now have a system that has database dependencies but does not know where to connect. Add Database Configuration for PostgreSQL It will likely fail because you do not have a PostgreSQL database configured. Running mvnw will download Maven, all dependencies, and run the application goal ( spring-boot:run). NOTE: Depending on your operating system, you might need to change. You can use Spring Initialzr for this.Ĭonfigure your project, as shown in the image above:ĭownload the file and unzip it. Create a Spring Boot App With PostgreSQLįirst, you need to create a new project with the required dependencies. Keep in mind, you are not creating a volume for the storage data if the container is deleted, all its data will be deleted as well. The last line executes a DDL command to create the database coursedb into the instance. The first line pulls PostgreSQL version 11 the second line initiates a new instance of it with the name dev-postgres, running on port 5432. The command above should run in any Linux, Windows, or MacOS distribution that has an instance of Docker installed. NOTE: You will need Docker installed for these commands to work. To install and test PostgreSQL, I recommend using Docker: docker pull postgres:11ĭocker run -name dev-postgres -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -d postgres:11ĭocker exec dev-postgres psql -U postgres -c"CREATE DATABASE coursedb" postgres You will need PostgreSQL installed to complete the tutorial. Why is that? Postgres means Post Ingres, or the successor of Ingres, an older database that paved the way to the more famous Microsoft SQL Server and other products. Technically speaking, it is also one of the most advanced relational database systems available. PostgreSQL is one of the most famous RDBMS around. A critical characteristic of RDBMS is the support for ACID transactions (Atomicity, Consistency, Isolation, Durability), which guarantee data consistency even in a concurrent environment without the developer needing to be fully aware. Initially proposed in the 70s, the RDBMS (Relational Database Management System) has grown in popularity through the years as computing processing power and storage capacity has increased. Let’s dig in! Get Started With PostgreSQL via Docker To finish, you will learn how to use PostgreSQL JSONB data structure and use PostgreSQL as a NoSQL database. I’ll also show you how to create SQL files to deliver database changes, which are more suitable for enterprise applications. In this tutorial, you are going to learn more about Postgres and how to integrate it with a Spring Boot application. Postgres is one of the most popular database tools used by Spring Boot devs.
0 Comments
Read More
Leave a Reply. |