-
Notifications
You must be signed in to change notification settings - Fork 1
Open
1 / 11 of 1 issue completedDescription
🎯 Purpose: Connect the Spring Boot application to a real PostgreSQL
database.
1️⃣ Install PostgreSQL
- Download from postgresql.org/download.
- During installation: User: postgres Password: postgres Database: user
- Verify that the database is created using pgAdmin.
2️⃣ Configure the project
- Add the following to src/main/resources/application.properties:
spring.datasource.url=jdbc:postgresql://localhost:5432/test_database
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.show-sql=true
- Ensure that the following dependencies exist in pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
3️⃣ Test the connection
- Add a simple REST endpoint:
@RestController
class DbTestController {
@Autowired DataSource ds;
@GetMapping("/api/test/db")
String test() throws Exception {
try (var c = ds.getConnection()) {
return "Connected to: " + c.getMetaData().getURL();
}
}
}
- Run the application and go to http://localhost:8080/api/test/db.
✅ Ifyou see “Connected to: jdbc:postgresql://localhost:5432/test_database”, the
connection is successful.
Acceptance Criteria:
-
PostgreSQL installed and running.
-
Application connects successfully.
-
REST endpoint confirms DB connection.
Sub-issues
Metadata
Metadata
Assignees
Labels
No labels