我正在使用DB PostgreSQL创建一个Spring Boot应用程序。我的application.properties
如下所示:
## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.url=jdbc:postgresql://localhost:5432/my-db
spring.datasource.username= myusername
spring.datasource.password= mypassword
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = update
依赖项:
<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>
简单模型:
@Entity
@Table(name = "questions")
@Data
public class Question {
@Id
@GeneratedValue(generator = "question_generator")
@SequenceGenerator(
name = "question_generator",
sequenceName = "question_sequence",
initialValue = 1000
)
private Long id;
@NotBlank
@Size(min = 3, max = 100)
private String title;
@Column(columnDefinition = "text")
private String description;
}
存储库:
@Repository
public interface QuestionRepository extends JpaRepository<Question, Long> {
}
和控制器:
@RestController
public class QuestionController {
@Autowired
private QuestionRepository questionRepository;
@GetMapping("/questions")
public Page<Question> getQuestions(Pageable pageable) {
return questionRepository.findAll(pageable);
}
}
当我尝试运行该应用程序时,它引发了一个错误:
由以下原因引起:org.hibernate.exception.GenericJDBCException:无法 打开JDBC连接以执行DDL
原因: org.postgresql.util.PSQLException:此结果集已关闭。
有人可以给我小费我在配置中做错了什么吗?非常感谢您!