【问题标题】:IllegalStateException: Unable to create a ConnectionFactory forIllegalStateException:无法创建 ConnectionFactory
【发布时间】:2023-01-13 13:24:13
【问题描述】:

当我尝试使用如下非反应性方法时,我能够毫无问题地建立连接。

spring.datasource.url=jdbc:sqlserver://AAAAA1011.na.app.corp\\bbbb;databaseName=mydb;integratedSecurity=true;authenticationScheme=JavaKerberos

但是当我尝试使用 Reactive R2dbc 和 MsSql 服务器方法时,如下所示,然后我面临异常,下面是代码:

@Bean
@Override
public ConnectionFactory connectionFactory() {

    ConnectionFactory connectionFactory = ConnectionFactories.get(ConnectionFactoryOptions.builder()
            .option(ConnectionFactoryOptions.DRIVER, "mssql")
            .option(ConnectionFactoryOptions.HOST, "AAAAA1011.na.app.corp/bbbb")
            .option(ConnectionFactoryOptions.DATABASE, "mydb")
            .option(ConnectionFactoryOptions.USER, "NA\\user")
            .option(Option.valueOf("integratedSecurity"), true)
            .option(Option.valueOf("authenticationScheme"), "JavaKerberos")
            .build());


    return connectionFactory;
}`

异常堆栈跟踪:

 org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.r2dbc.spi.ConnectionFactory]: Factory method 'connectionFactory' threw exception; nested exception is java.lang.IllegalStateException: Unable to create a ConnectionFactory for 'ConnectionFactoryOptions{options={database=mydb, host=AAAAA1011.na.app.corp/bbbb, driver=mssql, authenticationScheme=JavaKerberos, integratedSecurity=true, user=NA\user}}'. Available drivers: [ pool, sqlserver ]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.23.jar:5.3.23]

我找到了这个链接:https://github.com/r2dbc/r2dbc-mssql/issues/101 ,提到 r2dbc 似乎不支持 Kerberos,但那是在 2019 年写的,现在已经 3 年了,不确定上面是否有效。

如果有人知道上述问题,你能帮帮我吗..

【问题讨论】:

  • 好吧,票证仍然开放,所以没有 kerberos 支持。只有用户/密码。

标签: spring spring-boot reactive-programming spring-webflux spring-data-r2dbc


【解决方案1】:

从异常信息来看,连接问题是由驱动程序设置引起的。

可用的驱动程序:[ pool, sqlserver ]

尝试将 .option(ConnectionFactoryOptions.DRIVER, "mssql") 更改为以下内容:

.option(ConnectionFactoryOptions.DRIVER, "sqlserver")

我对 R2dbc/MSSQL 中的 Kerberos 支持知之甚少,请根据官方文档更新自己。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-04
    • 1970-01-01
    • 1970-01-01
    • 2022-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-06
    相关资源
    最近更新 更多