简体   繁体   English

r2dbc ReactiveCrudRepository 不断崩溃

[英]r2dbc ReactiveCrudRepository keeps crashing

My pom.xml has the following dependencies:我的 pom.xml 具有以下依赖项:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-r2dbc</artifactId>
  <version>2.3.3.RELEASE</version><!--$NO-MVN-MAN-VER$-->
</dependency>       

<dependency>
            <groupId>io.r2dbc</groupId>
            <artifactId>r2dbc-mssql</artifactId>
            <scope>runtime</scope>
</dependency>

My properties looks like:我的属性看起来像:

spring.r2dbc.url=r2dbc:mssql://localhost:1433/Admin
spring.r2dbc.username=xxx
spring.r2dbc.password=xxx

Repo looks like:回购看起来像:

@Repository
public interface UserRepository extends ReactiveCrudRepository<MyUser, String> {
    @Query("SELECT u.Username AS username, u.Password as password FROM Users u INNER JOIN Roles r ON u.RoleId=r.Roleid WHERE u.Username=@username") 
    public Mono<UserDetails> findByUsername(String username);
}

MyUser looks like: MyUser 看起来像:

@SuppressWarnings("serial")
public class MyUser implements UserDetails {

    @Id
    private String username;
    private String password;

    public MyUser(String username, String password) {
        this.username = username;
        this.password = password;
    }
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

I turned on the SQL profiler and caught the query coming in, and it is 100% correct and returns the correct data, but it seems to be crashing on the deserialization.我打开了 SQL 分析器并捕获了进来的查询,它 100% 正确并返回正确的数据,但它似乎在反序列化时崩溃了。 I set a breakpoint and it never calls the MyUser contructor.我设置了一个断点,它从不调用 MyUser 构造函数。 If I manually create one with Mono.just(), the app works as expected.如果我使用 Mono.just() 手动创建一个,该应用程序将按预期工作。

I am getting the following exception:我收到以下异常:

java.lang.NullPointerException: null
    at org.springframework.data.r2dbc.core.DefaultDatabaseClient$DefaultTypedExecuteSpec.lambda$new$0(DefaultDatabaseClient.java:590) ~[spring-data-r2dbc-1.1.3.RELEASE.jar:1.1.3.RELEASE]
    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
    |_ checkpoint ⇢ org.springframework.security.web.server.authentication.AuthenticationWebFilter [DefaultWebFilterChain]
    |_ checkpoint ⇢ org.springframework.security.web.server.authentication.AuthenticationWebFilter [DefaultWebFilterChain]
    |_ checkpoint ⇢ org.springframework.security.web.server.context.ReactorContextWebFilter [DefaultWebFilterChain]
    |_ checkpoint ⇢ org.springframework.security.web.server.header.HttpHeaderWriterWebFilter [DefaultWebFilterChain]
    |_ checkpoint ⇢ org.springframework.security.config.web.server.ServerHttpSecurity$ServerWebExchangeReactorContextWebFilter [DefaultWebFilterChain]
    |_ checkpoint ⇢ org.springframework.security.web.server.WebFilterChainProxy [DefaultWebFilterChain]
    |_ checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
    |_ checkpoint ⇢ HTTP POST "/login?error" [ExceptionHandlingWebHandler]
Stack trace:
        at org.springframework.data.r2dbc.core.DefaultDatabaseClient$DefaultTypedExecuteSpec.lambda$new$0(DefaultDatabaseClient.java:590) ~[spring-data-r2dbc-1.1.3.RELEASE.jar:1.1.3.RELEASE]
        at java.base/java.util.function.BiFunction.lambda$andThen$0(BiFunction.java:70) ~[na:na]
        at io.r2dbc.mssql.MssqlResult.lambda$map$2(MssqlResult.java:169) ~[r2dbc-mssql-0.8.4.RELEASE.jar:0.8.4.RELEASE]

Any ideas on the what the issue is?关于问题是什么的任何想法? The exception is on this block of code:例外是在这个代码块上:

    if (typeToRead.isInterface()) {
        this.mappingFunction = ColumnMapRowMapper.INSTANCE
                .andThen(map -> projectionFactory.createProjection(typeToRead, map));
    } else {
        this.mappingFunction = dataAccessStrategy.getRowMapper(typeToRead);
    }
  1. If you are using the Repository, in your codes, MyUser is not annotated with @Table , eg here如果您使用的是存储库,则在您的代码中, MyUser未使用@Table注释,例如此处

  2. You could try to use DatabaseClient to handle the query manually if you do not use the OR Mapping provided in Spring Data R2dbc, it is more flexible if you are stick on writing custom SQL scripts.如果您不使用 Spring Data R2dbc 中提供的 OR Mapping,您可以尝试使用DatabaseClient手动处理查询,如果您坚持编写自定义 SQL 脚本,它会更灵活。 eg.例如。 here . 在这里

尝试向 MyUser 类添加一个默认构造函数(一个没有参数的构造函数)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM