调用存储库上下文时 Micronaut 错误不包含密钥:io.micronaut.tx.STATUS
Micronaut error on calling repositry Context does not contain key: io.micronaut.tx.STATUS
import io.micronaut.core.annotation.NonNull;
import io.micronaut.data.annotation.GeneratedValue;
import io.micronaut.data.annotation.Id;
import io.micronaut.data.annotation.MappedEntity;
import io.micronaut.data.model.query.builder.sql.Dialect;
import io.micronaut.data.r2dbc.annotation.R2dbcRepository;
import io.micronaut.data.repository.reactive.ReactiveStreamsCrudRepository;
import io.micronaut.http.annotation.Body;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.http.annotation.Post;
import io.micronaut.runtime.Micronaut;
import lombok.RequiredArgsConstructor;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
public class Application {
public static void main(String[] args) {
Micronaut.run(Application.class, args);
}
}
@Controller
@RequiredArgsConstructor
class CustomerController {
private final CustomerRepository customerRepository;
@Get
public Flux<Customer> getAll() {
return customerRepository.findAll();
}
@Get("/test")
public Mono<Customer> test() {
return Mono.from(customerRepository.findById(1L)).map(e -> {
System.out.println(e);
return e;
});
// System.out.println(customerRepository);
// return Mono.just("TEST");
}
@Post
public Mono<Customer> create(@Body Customer customer) {
Customer saveCustomer = new Customer(customer.getName(), customer.getSurname());
return Mono.from(customerRepository.save(saveCustomer));
}
}
//@R2dbcRepository(dialect = Dialect.SQL_SERVER)
interface CustomerRepository extends ReactiveStreamsCrudRepository<Customer, Long> {
// @NonNull
// @Override
// Mono<Customer> findById(@NonNull @NotNull Long id);
//
// @NonNull
// @Override
// Mono<Customer> save(@NonNull @NotNull Customer customer);
//
@NonNull
@Override
Flux<Customer> findAll();
}
@MappedEntity("customer")
class Customer {
@Id
@GeneratedValue
private Long id;
private final String name;
private final String surname;
public Customer(String name, String surname) {
this.name = name;
this.surname = surname;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public String getSurname() {
return surname;
}
}
**
尝试通过端点调用存储库但不断出错
**
Context does not contain key: io.micronaut.tx.STATUS
at reactor.util.context.Context1.get(Context1.java:67)
at io.micronaut.data.r2dbc.operations.DefaultR2dbcRepositoryOperations.lambda$withTransaction(DefaultR2dbcRepositoryOperations.java:441)
at reactor.core.publisher.FluxDeferContextual.subscribe(FluxDeferContextual.java:49)
at reactor.core.publisher.InternalFluxOperator.subscribe(InternalFluxOperator.java:62)
at reactor.core.publisher.FluxDefer.subscribe(FluxDefer.java:54)
at reactor.core.publisher.InternalFluxOperator.subscribe(InternalFluxOperator.java:62)
我遇到过同样的问题。
检查这个:
@Get
public Flowable<Customer> getAll() {
return Flowable.fromPublisher(customerRepository.findAll());
}
Mono
在哪里使用 Single.fromPublisher(yourMono)
我在 micronaut 3 中遇到了同样的问题。
经过一些测试,我发现,在我的具体情况下,这个问题是由使用以下模块引起的:
micronaut-security-jwt
micronaut-reactor
micronaut-jackson-xml
如果删除所有这些依赖项,问题就会消失。
我认为这个问题是由上述 micronaut 模块引起的,所以 i opened an issue 在 micronaut-r2dbc github 页面上希望他们尽快解决这个问题。
编辑:
他们修复了这个错误,发布了新的 micronaut 版本 3.0.1!!!
import io.micronaut.core.annotation.NonNull;
import io.micronaut.data.annotation.GeneratedValue;
import io.micronaut.data.annotation.Id;
import io.micronaut.data.annotation.MappedEntity;
import io.micronaut.data.model.query.builder.sql.Dialect;
import io.micronaut.data.r2dbc.annotation.R2dbcRepository;
import io.micronaut.data.repository.reactive.ReactiveStreamsCrudRepository;
import io.micronaut.http.annotation.Body;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.http.annotation.Post;
import io.micronaut.runtime.Micronaut;
import lombok.RequiredArgsConstructor;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
public class Application {
public static void main(String[] args) {
Micronaut.run(Application.class, args);
}
}
@Controller
@RequiredArgsConstructor
class CustomerController {
private final CustomerRepository customerRepository;
@Get
public Flux<Customer> getAll() {
return customerRepository.findAll();
}
@Get("/test")
public Mono<Customer> test() {
return Mono.from(customerRepository.findById(1L)).map(e -> {
System.out.println(e);
return e;
});
// System.out.println(customerRepository);
// return Mono.just("TEST");
}
@Post
public Mono<Customer> create(@Body Customer customer) {
Customer saveCustomer = new Customer(customer.getName(), customer.getSurname());
return Mono.from(customerRepository.save(saveCustomer));
}
}
//@R2dbcRepository(dialect = Dialect.SQL_SERVER)
interface CustomerRepository extends ReactiveStreamsCrudRepository<Customer, Long> {
// @NonNull
// @Override
// Mono<Customer> findById(@NonNull @NotNull Long id);
//
// @NonNull
// @Override
// Mono<Customer> save(@NonNull @NotNull Customer customer);
//
@NonNull
@Override
Flux<Customer> findAll();
}
@MappedEntity("customer")
class Customer {
@Id
@GeneratedValue
private Long id;
private final String name;
private final String surname;
public Customer(String name, String surname) {
this.name = name;
this.surname = surname;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public String getSurname() {
return surname;
}
}
** 尝试通过端点调用存储库但不断出错 **
Context does not contain key: io.micronaut.tx.STATUS
at reactor.util.context.Context1.get(Context1.java:67)
at io.micronaut.data.r2dbc.operations.DefaultR2dbcRepositoryOperations.lambda$withTransaction(DefaultR2dbcRepositoryOperations.java:441)
at reactor.core.publisher.FluxDeferContextual.subscribe(FluxDeferContextual.java:49)
at reactor.core.publisher.InternalFluxOperator.subscribe(InternalFluxOperator.java:62)
at reactor.core.publisher.FluxDefer.subscribe(FluxDefer.java:54)
at reactor.core.publisher.InternalFluxOperator.subscribe(InternalFluxOperator.java:62)
我遇到过同样的问题。
检查这个:
@Get
public Flowable<Customer> getAll() {
return Flowable.fromPublisher(customerRepository.findAll());
}
Mono
在哪里使用 Single.fromPublisher(yourMono)
我在 micronaut 3 中遇到了同样的问题。 经过一些测试,我发现,在我的具体情况下,这个问题是由使用以下模块引起的:
micronaut-security-jwt
micronaut-reactor
micronaut-jackson-xml
如果删除所有这些依赖项,问题就会消失。 我认为这个问题是由上述 micronaut 模块引起的,所以 i opened an issue 在 micronaut-r2dbc github 页面上希望他们尽快解决这个问题。
编辑: 他们修复了这个错误,发布了新的 micronaut 版本 3.0.1!!!