ReactiveRepository.save() 在 Couchbase 中不起作用(扩展 ReactiveCrudRepository)

ReactiveRepository.save() does not work in Couchbase (extending ReactiveCrudRepository)

我无法将文档保存到 couchbase。

这是我的代码库。 我是 运行 docker 的沙发床。

我使用查询在数据库中手动添加了一个文档。

repo.findAll() 工作正常但 repo.save(person) 不工作。

有人可以帮我解决这个问题吗?

Person.java

@Document
@Getter
@Setter
@AllArgsConstructor
public class Person {

    @Id
    private String id;

    @Field
    @NotNull
    private String firstName;

    @Field
    @NotNull
    private String lastName;

    @Field
    @NotNull
    private String created;

    @Field
    private String updated;
}

PersonRepository.java

public interface PersonRepository extends ReactiveCrudRepository<Person,String> {
    Flux<Person> findByFirstName(String firstName);
    Flux<Person> findByLastName(String lastName);
}

PersonService.java

public interface PersonService {

   @View(designDocument = "_design/person",viewName = "all")
   Flux<Person> findAll();

   Flux<Person> findByFirstName(String firstName);

   Flux<Person> findByLastName(String lastName);

   void create(Person person);
}

PersonRepositoryService.java

@Service
@Slf4j
public class PersonRepositoryService implements PersonService{

    @Autowired
    private PersonRepository repo;

    @Override
    public Flux<Person> findAll() {
       return repo.findAll();
    }

    public Flux<Person> findByFirstName(String firstName){
        return repo.findByFirstName(firstName);
    }

    @Override
    public Flux<Person> findByLastName(String lastName) {
       return repo.findByLastName(lastName);
    }

    public void create(Person person){
       person.setCreated(LocalDateTime.now().toString());
       repo.save(person);
    }
}

ICustomerAccountAPI.java

@RequestMapping("/customerAccountManagement/v1/")
public interface ICustomerAccountAPI {

    @PostMapping(value = "/createProfile", consumes = APPLICATION_JSON)
    @ResponseStatus(HttpStatus.OK)
    Mono<Person> createCustomerProfile(@RequestBody @Valid Mono<Person> person);
}

CustomerAccountAPI.java

@RestController
@Slf4j
public class CustomerAccountAPI implements ICustomerAccountAPI {

   @Autowired PersonRepositoryService personRepositoryService;

   @Override
   public Mono<Person> createCustomerProfile(@RequestBody Mono<Person> person) {

       return person.map( person1 ->{
           personRepositoryService.create(person1);
           return person1;
       });
}

这些是我在POM中添加的与此相关的依赖。

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-couchbase</artifactId>
        <version>3.0.5.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>com.couchbase.client</groupId>
        <artifactId>java-client</artifactId>
        <version>2.5.6</version>
    </dependency>

    <dependency>
        <groupId>io.reactivex</groupId>
        <artifactId>rxjava-reactive-streams</artifactId>
        <version>0.3.0</version>
    </dependency>

请看我的回答:

这是同样的问题:没有任何反应,因为没有人订阅此发布者 (Mono)。返回 Mono ( repo.save(person) ) 作为 Spring 控制器的响应将解决问题。 Spring 将订阅该 Mono,将调用 repo.save(person) 方法,然后 Spring 将发送 HTTP 响应。