简体   繁体   中英

How to use simple JPA on Spring Boot

i am learning Spring Boot and trying to test the JPA

i have taken the " https://spring.io/guides/gs/accessing-data-jpa/ " exemple

and i have also tried on a simple initializr project with only data-jpa and h2

But i always got the same error

Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:

Property: driverclassname
Value: org.postgresql.Driver
Origin: "driverClassName" from property source "source"
Reason: Failed to load driver class org.postgresql.Driver in either of HikariConfig class loader or Thread context classloader

Action:

Update your application's configuration

i have read many post about this but it always come with a lot of different configurations and solutions

the fact is, it's just a simple program from 0, taken from initializr or the getting started course it should work with no specific configuration (i guess)

is that a computer configuration that is missing or do i really need to add a lot of application properties to make it work?

thank you

(sorry for my bad english ^^')

The link which you shared doesn't talk about DB configuration.

Spring Boot requires DB configuration at boot time.

Please add following config in application.properties

spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=username
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

Refer here for more detail

Add the next properties to your application.properties file

spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

Add a data.sql file in src/main/resources with the next content:

DROP TABLE IF EXISTS customer;

CREATE TABLE customer (
  id INT AUTO_INCREMENT  PRIMARY KEY,
  first_name VARCHAR(250) NOT NULL,
  last_name VARCHAR(250) NOT NULL
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM