我无法将文档保存到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>