我正在尝试用教程学习Sping Boot 。我有代码和数据库,但是每当我试图连接这两个时,我总是得到Hibernate错误...
这是我得到的错误:
:: Spring Boot :: (v2.7.2)
2022-08-04 19:23:59.263 INFO 13108 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1746 ms
2022-08-04 19:23:59.463 INFO 13108 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-08-04 19:24:00.560 ERROR 13108 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
我在pom.xml中设置了依赖项:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</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>
学生服务
@Service
public class StudentService {
public List<Student> getStudents() {
return List.of(
new Student(
1L,
"Mariam",
"mariam.jamal@gmail.com",
LocalDate.of(2000, Month.JANUARY, 5),
21
)
);
}
}
学生控制器类
@RestController
@RequestMapping(path = "api/v1/student")
public class StudentController {
private final StudentService studentService;
@Autowired
public StudentController(StudentService studentService) {
this.studentService = studentService;
}
@GetMapping
public List<Student> getStudents() {
return studentService.getStudents();
}
}
application.properties:
spring.datasource.url=jdbc:postgresql://localhost:5432/student
spring.datasource.username=postgres
spring.datasouce.password=password
spring.jpa.hibernat.ddl-auto=create-drop
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.format_sql=true
不幸的是,我不知道是什么问题,也不知道我能做些什么来改善它。我在谷歌上搜索,但只找到了“密码没有填写”(事实并非如此)和“application.properties不在资源文件夹中”(他们是...)
非常感谢你已经看过它,如果我能澄清任何事情,我很高兴这样做。
编辑:对不起张贴它作为图片,我取代了一切,但错误代码,如果我应该改变,太告诉我
如果我是正确的,PostgreSQL的版本是14.4 pg_hba.config中的文本:
# PostgreSQL Client Authentication Configuration File
# ===================================================
#
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all scram-sha-256
# IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
# IPv6 local connections:
host all all ::1/128 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all scram-sha-256
host replication all 127.0.0.1/32 scram-sha-256
host replication all ::1/128 scram-sha-256
1条答案
按热度按时间wgmfuz8q1#
我现在已经修复了它。问题是我在application.properties中写的是
hibernat
而不是hibernate
。