0

My connection config:

@Configuration @EnableR2dbcRepositories public class DatabaseConfiguration extends AbstractR2dbcConfiguration { @Bean public PostgresqlConnectionFactory connectionFactory() { return new PostgresqlConnectionFactory(PostgresqlConnectionConfiguration.builder() .host("r2dbc:postgresql://mydb.alfa") .port(5432) .username("admin") .database("postgres") .password(password) .build() ); } } 

My repository:

public interface ReactiveOdometerRepository extends ReactiveCrudRepository<OdometerEntity, String> { Flux<OdometerEntity> findTop1By(String name); } 

My entity:

@Setter public class OdometerEntity { @Getter @Id private String name; @Getter private int value; } 

When I try querying the DB, it fails:

@PostMapping(value = "/query", produces = MediaType.APPLICATION_JSON_VALUE) public int get(@RequestBody RequestObject request) { return odometerRepository.findTop1ByName(request.getName()).getValue(); 

Error:

io.r2dbc.postgresql.PostgresqlConnectionFactory$PostgresConnectionException: Cannot connect to r2dbc:postgresql://mydb.alfa/<unresolved>:5432 

Not sure what the unresolved is doing in there.

How do I fix this error? thanks

2
  • 1
    I would expect the host property to contain the name of the host, not the full URL. So I would expect host("mydb.alfa"). Commented Nov 16, 2022 at 7:58
  • thanks, this fixed the problem. please feel free to add this as an answer and i'll accept it. or i can create the answer for you. Commented Nov 16, 2022 at 21:35

2 Answers 2

1

Your host variable is wrong. It should contain only the name or ip-address of the host not the full URL.

So instead of host("r2dbc:postgresql://mydb.alfa") use host("mydb.alfa").

@Bean public PostgresqlConnectionFactory connectionFactory() { return new PostgresqlConnectionFactory(PostgresqlConnectionConfiguration.builder() .host("mydb.alfa") .port(5432) .username("admin") .database("postgres") .password(password) .build() ); } 
Sign up to request clarification or add additional context in comments.

Comments

1

You have to specify host name in the host, not the url there

 PostgresqlConnectionFactory( PostgresqlConnectionConfiguration.builder() .host("localhost") .database("blogdb") .username("user") .password("password") .codecRegistrar( EnumCodec .builder() .withEnum("post_status", Post.Status.class) .build() ) .build() ) 

There are a few r2dbc connectionfactory examples from my Github.

1 Comment

thanks for sharing the samples. I wish I had these when i was writing the code initially!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.