代码之家  ›  专栏  ›  技术社区  ›  fakhruddin tahery

反应性存储。save()在Couchbase中不起作用(扩展ReactiveCrudRepository)

  •  1
  • fakhruddin tahery  · 技术社区  · 8 年前

    我无法将文档保存到couchbase。

    这是我的代码库。 我在docker经营couchbase。

    我使用query在DB中手动添加了一个文档。

    回购。findAll()工作正常,但需要回购。保存(个人)不起作用。

    有人能帮我一下吗?

    人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);
    }
    

    个人服务。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>
    
    1 回复  |  直到 8 年前
        1
  •  2
  •   mroman    8 年前

    请看我的答案: updating object with spring data mongodb and kotlin is not working

    这是同一个问题:没有人订阅此发布服务器(Mono),所以什么都没有发生。返回单声道( repo.save(person) )由于Spring控制器的响应将解决该问题。Spring将订阅Mono,即回购协议。将调用save(person)方法,然后Spring将发送HTTP响应。