0

When trying to initialize the application, I got an error.

r2dbc + Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.r2dbc.pool.ConnectionPool]: Factory method 'connectionFactory' threw exception with message: Unable to create a ConnectionFactory for 'ConnectionFactoryOptions{options={database=company, host=127.0.0.1, driver=postgresql, password=REDACTED, port=5433, user=postgres}}'. Available drivers: [ pool ]

I found a solution, maybe it will be useful to someone. (for migrating scripts for databases, flywaydb is used)

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-r2dbc</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-core</artifactId>
    <version>9.16.1</version>
</dependency>

<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>r2dbc-postgresql</artifactId>
    <scope>runtime</scope>
</dependency>

<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <scope>runtime</scope>
</dependency>

  • application.yaml
DB_IP: 127.0.0.1
DB_PORT: 5432
DB_DATABASE_NAME: db
DB_SCHEMA: public

database:
  url: postgresql://localhost:5432/db

server:
  port: 8090
  error:
    include-message: always

spring:
  r2dbc:
    username: postgres 
    password: postgres 
    url: r2dbc:postgresql://127.0.0.1:5432/db

  flyway:
    baseline-description: true
    baseline-on-migrate: true
    create-schemas: true
    enabled: true
    default-schema: ${DB_SCHEMA}
    locations: classpath:db/migration
    password: ${spring.r2dbc.password}
    schemas: public
    url: jdbc:${database.url}
    user: ${spring.r2dbc.username}
    validate-on-migrate: true

skyho
  • 1,438
  • 2
  • 20
  • 47

0 Answers0