0

I am configuring r2db-mysql application with yaml , but its run error when i try to connect mysql

here is my yaml config

spring:
  r2dbc:
    url: r2dbc:mysql://localhost:3306/schema?useUnicode=true&characterEncoding=utf-8&txcAppName=account&useSSL=true
    username: root
    password: root

here is error stack

Caused by: java.lang.IllegalStateException: Unable to create a ConnectionFactory for 'ConnectionFactoryOptions{options={database=schema, host=localhost, driver=mysql, useUnicode=true, characterEncoding=utf-8, password=REDACTED, port=3306, txcAppName=account, useSSL=true, user=ifx}}'. Available drivers: [ pool ]
    at io.r2dbc.spi.ConnectionFactories.get(ConnectionFactories.java:145)
    at org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryBuilder.build(ConnectionFactoryBuilder.java:125)
    at org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryConfigurations.createConnectionFactory(ConnectionFactoryConfigurations.java:56)
    at org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryConfigurations$Pool.connectionFactory(ConnectionFactoryConfigurations.java:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    ... 84 common frames omitted

Due to the failure configuration experience with yaml, i try to according to [offical article] (https://github.com/mirromutth/r2dbc-mysql) to configurate in spring with java bean ,and its success here is code sample

 @Bean
    public ConnectionFactory initConnectionFactory(@Autowired R2dbcProperties r2dbcProperties){
        ConnectionFactory pooledConnectionFactory = ConnectionFactories.get(ConnectionFactoryOptions.builder()
                .option(DRIVER,"mysql")
    //            .option(PROTOCOL,"mysql") // driver identifier, PROTOCOL is delegated as DRIVER by the pool.
                .option(HOST,"xxxx")
                .option(PORT,3306)
                .option(USER,"root")
                .option(PASSWORD,"root")
                .option(DATABASE,"schema")
                .build());
        return pooledConnectionFactory;
    }
Peng
  • 653
  • 8
  • have yout tried `url: r2dbc:pool:mysql://localhost:3306/schema?useUnicode=true&characterEncoding=utf-8&txcAppName=account&useSSL=true` ? – kerbermeister Feb 14 '23 at 16:31
  • you remind me! ,i forgot add reactice database dependency, after add the ```r2dbc-mysql``` dependency , and replace ```pool``` with ```mysql```,then mysql connection active – Peng Feb 15 '23 at 01:31

0 Answers0