I connected my Postgres database with Spring Boot but something when wrong. I didn't show any error but it didn't go into the database. *I have replace my Postgres URL with $URl and $password for security issue.
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.hikari.connectionTimeout=20000
spring.datasource.hikari.maximumPoolSize=5
spring.datasource.url=jdbc:postgresql://$URL:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=$password
spring.jpa.hibernate.ddl-auto=create
and the result was only these
2021-12-08 17:31:03.430 INFO 4216 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication using Java 17.0.1 on DESKTOP with PID 4006 (C:\Users\Thanh Lu\Desktop\demo\target\classes started by Thanh Lu in C:\Users\Any\Desktop\demo)
2021-12-08 17:31:03.431 INFO 4216 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2021-12-08 17:31:03.655 INFO 4216 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 0.378 seconds (JVM running for 0.634)
and my Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Any advice would be appreciate.
Thanks in advance
CodePudding user response:
I can't find JPA/Hibernate dependency in your Maven pom.xml. Try to add the following dependency there:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
CodePudding user response:
I think you have not used any object or config relate to database. Simple, you can try create entity then add following 2 configuration in file application.properties
logging.level.com.zaxxer.hikari.HikariConfig=DEBUG
logging.level.com.zaxxer.hikari=TRACE
And in your Maven pom.xml add dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>