반응형

필요한 라이브러리

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-r2dbc</artifactId>
</dependency>
<dependency>
    <groupId>io.asyncer</groupId>
    <artifactId>r2dbc-mysql</artifactId>
</dependency>
<dependency>
    <groupId>com.mysql</groupId>
    <artifactId>mysql-connector-j</artifactId>
    <scope>runtime</scope>
</dependency>

 

 

설정 코드 

@Configuration
@EnableR2dbcRepositories
public class R2DBCConfiguration extends AbstractR2dbcConfiguration {
    @Override
    @Bean
    public ConnectionFactory connectionFactory() {
        ConnectionFactory connectionFactory = ConnectionFactories.get(ConnectionFactoryOptions.builder()
                        .option(DRIVER, "mysql")
                        .option(HOST, "localhost")
                        .option(USER, "root")
                        .option(PASSWORD, "password")
                        .option(PORT, 3307)
                        .option(DATABASE, "db")
                                                    .build());
        return connectionFactory;
    }
}

와 같이 설정하면 db 연결된다.

세팅 및 설정 관련 문서

https://github.com/asyncer-io/r2dbc-mysql

반응형

+ Recent posts