我正在尝试将Cosmos DB Mongo API与Spring Data Mongo一起使用,但我似乎无法让它因某些原因而起作用。我接受了Spring Boot Data Mongo示例项目,并将其交换为指向我的Cosmos DB Mongo API实例并且我不断获取
"Errors":["The input name presented contains invalid character '='."]
代码:
@SpringBootApplication
public class Application implements CommandLineRunner {
@Autowired
private CustomerRepository repository;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
public void run(String... args) throws Exception {
repository.deleteAll();
// save a couple of customers
repository.save(new Customer("Alice", "Smith"));
repository.save(new Customer("Bob", "Smith"));
// fetch all customers
System.out.println("Customers found with findAll():");
System.out.println("-------------------------------");
for (Customer customer : repository.findAll()) {
System.out.println(customer);
}
System.out.println();
// fetch an individual customer
System.out.println("Customer found with findByFirstName('Alice'):");
System.out.println("--------------------------------");
System.out.println(repository.findByFirstName("Alice"));
System.out.println("Customers found with findByLastName('Smith'):");
System.out.println("--------------------------------");
for (Customer customer : repository.findByLastName("Smith")) {
System.out.println(customer);
}
}
}
-
public class Customer {
@Id
public String id;
public String firstName;
public String lastName;
public Customer() {}
public Customer(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
@Override
public String toString() {
return String.format(
"Customer[id=%s, firstName='%s', lastName='%s']",
id, firstName, lastName);
}
}
-
public interface CustomerRepository extends MongoRepository<Customer, String> {
public Customer findByFirstName(String firstName);
public List<Customer> findByLastName(String lastName);
}
这是完整的堆栈跟踪
Caused by: org.springframework.data.mongodb.UncategorizedMongoDbException: Command failed with error 2: 'Message: {"Errors":["The input name presented contains invalid character '='."]}
ActivityId: bbd7a66e-0000-0000-0000-000000000000, Request URI: /apps/514defcb-ac21-44e6-a8e0-c7b785523c6c/services/f173b6ae-dc85-49b6-aa62-47cd6a2e7502/partitions/77795815-5c06-4ded-a979-25c46b054119/replicas/131632137400221103p, RequestStats: , SDK: Microsoft.Azure.Documents.Common/1.20.0.0' on server bl4prdddc02-docdb-1.documents.azure.com:10255. The full response is { "_t" : "OKMongoResponse", "ok" : 0, "code" : 2, "errmsg" : "Message: {\"Errors\":[\"The input name presented contains invalid character '='.\"]}\r\nActivityId: bbd7a66e-0000-0000-0000-000000000000, Request URI: /apps/514defcb-ac21-44e6-a8e0-c7b785523c6c/services/f173b6ae-dc85-49b6-aa62-47cd6a2e7502/partitions/77795815-5c06-4ded-a979-25c46b054119/replicas/131632137400221103p, RequestStats: , SDK: Microsoft.Azure.Documents.Common/1.20.0.0", "$err" : "Message: {\"Errors\":[\"The input name presented contains invalid character '='.\"]}\r\nActivityId: bbd7a66e-0000-0000-0000-000000000000, Request URI: /apps/514defcb-ac21-44e6-a8e0-c7b785523c6c/services/f173b6ae-dc85-49b6-aa62-47cd6a2e7502/partitions/77795815-5c06-4ded-a979-25c46b054119/replicas/131632137400221103p, RequestStats: , SDK: Microsoft.Azure.Documents.Common/1.20.0.0" }; nested exception is com.mongodb.MongoCommandException: Command failed with error 2: 'Message: {"Errors":["The input name presented contains invalid character '='."]}
ActivityId: bbd7a66e-0000-0000-0000-000000000000, Request URI: /apps/514defcb-ac21-44e6-a8e0-c7b785523c6c/services/f173b6ae-dc85-49b6-aa62-47cd6a2e7502/partitions/77795815-5c06-4ded-a979-25c46b054119/replicas/131632137400221103p, RequestStats: , SDK: Microsoft.Azure.Documents.Common/1.20.0.0' on server bl4prdddc02-docdb-1.documents.azure.com:10255. The full response is { "_t" : "OKMongoResponse", "ok" : 0, "code" : 2, "errmsg" : "Message: {\"Errors\":[\"The input name presented contains invalid character '='.\"]}\r\nActivityId: bbd7a66e-0000-0000-0000-000000000000, Request URI: /apps/514defcb-ac21-44e6-a8e0-c7b785523c6c/services/f173b6ae-dc85-49b6-aa62-47cd6a2e7502/partitions/77795815-5c06-4ded-a979-25c46b054119/replicas/131632137400221103p, RequestStats: , SDK: Microsoft.Azure.Documents.Common/1.20.0.0", "$err" : "Message: {\"Errors\":[\"The input name presented contains invalid character '='.\"]}\r\nActivityId: bbd7a66e-0000-0000-0000-000000000000, Request URI: /apps/514defcb-ac21-44e6-a8e0-c7b785523c6c/services/f173b6ae-dc85-49b6-aa62-47cd6a2e7502/partitions/77795815-5c06-4ded-a979-25c46b054119/replicas/131632137400221103p, RequestStats: , SDK: Microsoft.Azure.Documents.Common/1.20.0.0" }
at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:107) ~[spring-data-mongodb-1.10.10.RELEASE.jar:na]
at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2139) ~[spring-data-mongodb-1.10.10.RELEASE.jar:na]
at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:484) ~[spring-data-mongodb-1.10.10.RELEASE.jar:na]
at org.springframework.data.mongodb.core.MongoTemplate.insertDBObject(MongoTemplate.java:1049) ~[spring-data-mongodb-1.10.10.RELEASE.jar:na]
at org.springframework.data.mongodb.core.MongoTemplate.doInsert(MongoTemplate.java:858) ~[spring-data-mongodb-1.10.10.RELEASE.jar:na]
at org.springframework.data.mongodb.core.MongoTemplate.insert(MongoTemplate.java:799) ~[spring-data-mongodb-1.10.10.RELEASE.jar:na]
at org.springframework.data.mongodb.repository.support.SimpleMongoRepository.save(SimpleMongoRepository.java:80) ~[spring-data-mongodb-1.10.10.RELEASE.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_162]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_162]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_162]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_162]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:513) ~[spring-data-commons-1.13.10.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:498) ~[spring-data-commons-1.13.10.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:475) ~[spring-data-commons-1.13.10.RELEASE.jar:na]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:56) ~[spring-data-commons-1.13.10.RELEASE.jar:na]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57) ~[spring-data-commons-1.13.10.RELEASE.jar:na]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at com.sun.proxy.$Proxy45.save(Unknown Source) ~[na:na]
at hello.Application.run(Application.java:24) [classes/:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:732) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
... 6 common frames omitted
Caused by: com.mongodb.MongoCommandException: Command failed with error 2: 'Message: {"Errors":["The input name presented contains invalid character '='."]}
ActivityId: bbd7a66e-0000-0000-0000-000000000000, Request URI: /apps/514defcb-ac21-44e6-a8e0-c7b785523c6c/services/f173b6ae-dc85-49b6-aa62-47cd6a2e7502/partitions/77795815-5c06-4ded-a979-25c46b054119/replicas/131632137400221103p, RequestStats: , SDK: Microsoft.Azure.Documents.Common/1.20.0.0' on server bl4prdddc02-docdb-1.documents.azure.com:10255. The full response is { "_t" : "OKMongoResponse", "ok" : 0, "code" : 2, "errmsg" : "Message: {\"Errors\":[\"The input name presented contains invalid character '='.\"]}\r\nActivityId: bbd7a66e-0000-0000-0000-000000000000, Request URI: /apps/514defcb-ac21-44e6-a8e0-c7b785523c6c/services/f173b6ae-dc85-49b6-aa62-47cd6a2e7502/partitions/77795815-5c06-4ded-a979-25c46b054119/replicas/131632137400221103p, RequestStats: , SDK: Microsoft.Azure.Documents.Common/1.20.0.0", "$err" : "Message: {\"Errors\":[\"The input name presented contains invalid character '='.\"]}\r\nActivityId: bbd7a66e-0000-0000-0000-000000000000, Request URI: /apps/514defcb-ac21-44e6-a8e0-c7b785523c6c/services/f173b6ae-dc85-49b6-aa62-47cd6a2e7502/partitions/77795815-5c06-4ded-a979-25c46b054119/replicas/131632137400221103p, RequestStats: , SDK: Microsoft.Azure.Documents.Common/1.20.0.0" }
at com.mongodb.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:115) ~[mongodb-driver-core-3.4.3.jar:na]
at com.mongodb.connection.WriteCommandProtocol.receiveMessage(WriteCommandProtocol.java:268) ~[mongodb-driver-core-3.4.3.jar:na]
at com.mongodb.connection.WriteCommandProtocol.execute(WriteCommandProtocol.java:104) ~[mongodb-driver-core-3.4.3.jar:na]
at com.mongodb.connection.InsertCommandProtocol.execute(InsertCommandProtocol.java:67) ~[mongodb-driver-core-3.4.3.jar:na]
at com.mongodb.connection.InsertCommandProtocol.execute(InsertCommandProtocol.java:37) ~[mongodb-driver-core-3.4.3.jar:na]
at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:168) ~[mongodb-driver-core-3.4.3.jar:na]
at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:289) ~[mongodb-driver-core-3.4.3.jar:na]
at com.mongodb.connection.DefaultServerConnection.insertCommand(DefaultServerConnection.java:118) ~[mongodb-driver-core-3.4.3.jar:na]
at com.mongodb.operation.InsertOperation.executeCommandProtocol(InsertOperation.java:76) ~[mongodb-driver-core-3.4.3.jar:na]
at com.mongodb.operation.BaseWriteOperation$1.call(BaseWriteOperation.java:139) ~[mongodb-driver-core-3.4.3.jar:na]
at com.mongodb.operation.BaseWriteOperation$1.call(BaseWriteOperation.java:133) ~[mongodb-driver-core-3.4.3.jar:na]
at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:426) ~[mongodb-driver-core-3.4.3.jar:na]
at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:417) ~[mongodb-driver-core-3.4.3.jar:na]
at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:133) ~[mongodb-driver-core-3.4.3.jar:na]
at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:60) ~[mongodb-driver-core-3.4.3.jar:na]
at com.mongodb.Mongo.execute(Mongo.java:845) ~[mongodb-driver-3.4.3.jar:na]
at com.mongodb.Mongo$2.execute(Mongo.java:828) ~[mongodb-driver-3.4.3.jar:na]
at com.mongodb.DBCollection.executeWriteOperation(DBCollection.java:342) ~[mongodb-driver-3.4.3.jar:na]
at com.mongodb.DBCollection.insert(DBCollection.java:337) ~[mongodb-driver-3.4.3.jar:na]
at com.mongodb.DBCollection.insert(DBCollection.java:328) ~[mongodb-driver-3.4.3.jar:na]
at com.mongodb.DBCollection.insert(DBCollection.java:298) ~[mongodb-driver-3.4.3.jar:na]
at com.mongodb.DBCollection.insert(DBCollection.java:264) ~[mongodb-driver-3.4.3.jar:na]
at com.mongodb.DBCollection.insert(DBCollection.java:201) ~[mongodb-driver-3.4.3.jar:na]
at org.springframework.data.mongodb.core.MongoTemplate$9.doInCollection(MongoTemplate.java:1054) ~[spring-data-mongodb-1.10.10.RELEASE.jar:na]
at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:482) ~[spring-data-mongodb-1.10.10.RELEASE.jar:na]
... 28 common frames omitted