Spring Data Jpa sporing Boot postgresql not creating配置文件

bkhjykvo  于 2024-01-09  发布在  Spring
关注(0)|答案(2)|浏览(296)

所以我有一个spring Boot 应用程序,并配置了postgresql,如下所示

  1. spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
  2. spring.datasource.url=jdbc:postgresql:dburl
  3. spring.datasource.username=admin
  4. spring.datasource.password=XXX

字符串
但我在应用程序启动时遇到失败,因为没有创建一个临时文件

  1. No qualifying bean of type 'javax.sql.DataSource' available


我决定创建一个虚拟bean:

  1. @Configuration
  2. public class DataSourceConfig {
  3. @Bean
  4. public DataSource dataSource() {
  5. // Create and configure the DataSource here
  6. DriverManagerDataSource dataSource = new DriverManagerDataSource();
  7. dataSource.setDriverClassName("org.hibernate.dialect.PostgreSQLDialect");
  8. dataSource.setUrl("jdbc:postgresql://localhost:5432/your-database");
  9. dataSource.setUsername("your-username");
  10. dataSource.setPassword("your-password");
  11. return dataSource;
  12. }
  13. }


这似乎建立了一种联系。
但是我不明白为什么我不能从属性中创建一个数组。

cig3rfwq

cig3rfwq1#

在给定的示例中,您缺少Postgres的端口号。
使用spring Boot 连接到Postgres非常简单。请尝试以下操作-
pom.xml

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-data-jpa</artifactId>
  4. </dependency>
  5. <dependency>
  6. <groupId>org.postgresql</groupId>
  7. <artifactId>postgresql</artifactId>
  8. <scope>runtime</scope>
  9. </dependency>

字符串
application.properties

  1. spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
  2. spring.jpa.hibernate.ddl-auto=update
  3. spring.jpa.hibernate.show-sql=true
  4. spring.datasource.url=jdbc:postgresql://localhost:5432/my-db
  5. spring.datasource.username=postgres
  6. spring.datasource.password=root

展开查看全部
weylhg0b

weylhg0b2#

你能给我们展示一下你的依赖吗?如果使用Maven作为你的构建工具,请检查你是否有这个(如果没有,请添加,然后重试):

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-data-jpa</artifactId>
  4. </dependency>

字符串

相关问题