Created
September 6, 2020 07:42
-
-
Save mainul35/2f8993029145f50940120801b214039c to your computer and use it in GitHub Desktop.
r2dbc postgresql connection with configuration class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@EnableR2dbcRepositories(basePackages = "com.mainul35.repositories") | |
public class DatabaseConfig extends AbstractR2dbcConfiguration { | |
@Value("${datasource.host}") | |
private String host; | |
@Value("${datasource.port}") | |
private int port; | |
@Value("${datasource.database}") | |
private String database; | |
@Value("${datasource.username}") | |
private String username; | |
@Value("${datasource.password}") | |
private String password; | |
@Bean | |
@Override | |
public PostgresqlConnectionFactory connectionFactory() { | |
return new PostgresqlConnectionFactory(PostgresqlConnectionConfiguration | |
.builder() | |
.host(host) | |
.database(database) | |
.username(username) | |
.password(password) | |
.port(port) | |
.build()); | |
} | |
// DatabaseClient will be required for executing queries | |
@Bean | |
public DatabaseClient databaseClient() { | |
return DatabaseClient.create(connectionFactory()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment