I wrote the following Spring Boot program. Everything works correctly, except for the last line that calls findOne().
I know I am connecting to the CB cluster, since I can see my documents appear there. The exists() method works correctly, so my code is seeing the documents in the bucket. The delete() method works. If I try findOne() for a non-existent document, it works correctly (returns a null). But when I try findOne() for an existing doc the code crashes with a “source not found” error.
This is a simple key-value lookup. FindOne() should not need a backing view or index.
TIA for any ideas.
Chuck
+++++++++++++++++++++
package demo;
import java.util.Arrays;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
@SpringBootApplication
public class Application {
private final static String CRUD_BEAN = "personRepository";
public static void main(String[] args) {
// Run the application and get its handle.
ApplicationContext ctx = SpringApplication.run(Application.class, args);
// Find all the Spring Boot beans.
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
// Get the bean for the Couchbase CRUD repository.
PersonRepository cb = (PersonRepository) ctx.getBean(CRUD_BEAN);
// Make some person records and save them to Couchbase. The save() operation may change the saved object.
Person p1 = new Person("001", "chuck", "connell");
p1 = cb.save(p1);
Person p2 = new Person("002", "jane", "smith");
p2 = cb.save(p2);
// Test the exists() method.
System.out.println (cb.exists("002")); // should be true
System.out.println (cb.exists("999")); // should be false
// Test the delete() method.
cb.delete("002");
System.out.println (cb.exists("002")); // should be false
// Retrieve a record using plain key/value. Should not need an index or view.
Person p3 = cb.findOne("001"); // !!!! THIS FAILS. WHY???
System.out.println (p3.getFirstname());
}
}
+++++++++++++++++++
package demo;
import com.couchbase.client.java.repository.annotation.Id;
import com.couchbase.client.java.repository.annotation.Field;
import org.springframework.data.couchbase.core.mapping.Document;
@Document
public class Person {
@Id
private String id;
@Field ("fname")
private String firstName;
@Field ("lname")
private String lastName;
public Person(String id, String firstname, String lastname) {
this.id = id;
this.firstName = firstname;
this.lastName = lastname;
}
public String getId() {
return id;
}
public String getFirstname() {
return firstName;
}
public String getLastname() {
return lastName;
}
}
++++++++++++++++
package demo;
import org.springframework.data.repository.CrudRepository;
public interface PersonRepository extends CrudRepository<Person, String> {
// custom methods here....
}
++++++++++++++++++++
package demo;
import java.util.Arrays;
import java.util.List;
import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories;
@Configuration
@EnableAutoConfiguration
@EnableCouchbaseRepositories
public class Config extends AbstractCouchbaseConfiguration {
@Override
protected List<String> getBootstrapHosts() {
return Arrays.asList("cb1");
}
@Override
protected String getBucketName() {
return "my-test";
}
@Override
protected String getBucketPassword() {
return "";
}
}
+++++++++++++++++++++++++
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>spring-boot-starters</artifactId>
<groupId>org.springframework.boot</groupId>
<version>1.4.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>spring-boot-starter-data-couchbase</artifactId>
<name>Spring Boot Data Couchbase Starter</name>
<description>Starter for using Couchbase document-oriented database and Spring Data
Couchbase</description>
<url>http://projects.spring.io/spring-boot/</url>
<organization>
<name>Pivotal Software, Inc.</name>
<url>http://www.spring.io</url>
</organization>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-couchbase</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.basepom.maven</groupId>
<artifactId>duplicate-finder-maven-plugin</artifactId>
<executions>
<execution>
<id>duplicate-dependencies</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<ignoredResourcePatterns>
<ignoredResourcePattern>changelog.txt</ignoredResourcePattern>
</ignoredResourcePatterns>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>