测试用例
.NET Upsert - > .NET GetDocument:成功
Spring Save - > Spring FindOne:成功
Spring Save - > .NET GetDocument:成功
4。 .NET Upsert - > Spring FindOne:失败
为什么我不知道......请帮帮我
.NET代码
var config = new ClientConfiguration
{
Servers = new List<Uri>
{
new Uri("http://127.0.0.1:8091/pools")
},
Serializer = () => new JilSerializer()
};
using (var cluster = new Cluster(config))
{
IBucket bucket = null;
try
{
bucket = cluster.OpenBucket("Test", "Test");
cItemInfo TempClass = new cItemInfo();
for (int i = 0; i < 3; i++)
{
TestClass temp = new TestClass();
temp.var1 = i;
temp.var2 = i;
temp.var3 = ".NET Testing";
TempClass.test.Add(temp);
}
TempClass.result = 200;
string jsonStr = JsonConvert.SerializeObject(TempClass);
var document = new Document<cItemInfo>();
document.Id = "TestClass_NET";
document.Content = TempClass;
var upsert = bucket.Upsert(document);
if (upsert.Success)
Console.WriteLine("Success");
Console.Read();
}
finally
{
if (bucket != null)
{
cluster.CloseBucket(bucket);
}
}
}
Spring Framework代码
// [WS_ItemInfo.java]
@RequestMapping("GetItemInfoEx")
public @ResponseBody C_ItemInfo GetItemInfoEx() {
C_ItemInfo item = itemInfo.getItemInfo("TestClass_NET");
return item;
}
// [CS_ItemInfo.java]
@Component
public class CS_ItemInfo {
@Autowired
private CR_ItemInfo itemInfo;
public void setItemInfo(C_ItemInfo item) {
itemInfo.save(item);
}
public C_ItemInfo getItemInfo(String uID) {
return itemInfo.findOne(uID);
}
public boolean getItemInfoExists(String uID) {
return itemInfo.exists(uID);
}
}
// [CR_ItemInfo.java]
public interface CR_ItemInfo extends CrudRepository<C_ItemInfo, String> {
}
// [CouchbaseConfig.java]
@EnableCouchbaseRepositories
@Configuration
public class CouchBaseConfig extends AbstractCouchbaseConfiguration {
@Override
protected List<String> bootstrapHosts() {
return Arrays.asList("127.0.0.1");
}
@Override
protected String getBucketName() {
return "test";
}
@Override
protected String getBucketPassword() {
return "test";
}
@Bean
public MappingCouchbaseConverter mappingCouchbaseConverter() throws Exception {
MappingCouchbaseConverter converter = new MyMappingCouchbaseConverter(couchbaseMappingContext());
converter.setCustomConversions(customConversions());
return converter;
}
private class MyMappingCouchbaseConverter extends MappingCouchbaseConverter {
public MyMappingCouchbaseConverter(
MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> mappingContext) {
super(mappingContext);
typeMapper = new DefaultCouchbaseTypeMapper(null);
}
}
}
答案 0 :(得分:0)
Spring Data Couchbase 1.4.2基于&#34;较旧的&#34;生成SDK(Java SDK 1.4.2)。这一代不支持SDK之间的交叉兼容性,并且是第二代SDK(.NET 2.2.2所属的,但不是Java 1.4.2)的焦点。
第二代Spring Data Couchbase 2.0.x目前是in Release Candidate,应该生成与.NET 2.2.2交叉兼容的文档。