我以下面的方式创建了收藏集</ p>
@Document(collection = "User")
public class User extends AbstractEntity{
private static final long serialVersionUID = 1L;
@NonNull
private String deviceId;
private GeoJsonPoint location;
public String getDeviceId() {
return deviceId;
}
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}
public GeoJsonPoint getLocation() {
return location;
}
public void setLocation(GeoJsonPoint location) {
this.location = location;
}
}
和存储库如下
public interface UserRepository extends MongoRepository<User, String> {
List<User> findAll();
User insert(User u);
}
当我添加具有以下位置的新用户时
User user1 = new User();
user1.setDeviceId("1010101010");
GeoJsonPoint locationPoint = new
GeoJsonPoint(53.10, 75.10);
user1.setLocation(locationPoint);
//user1.setLocation();
userRepository.save(user1);
Spring给出如下异常
原因: org.springframework.core.convert.ConverterNotFoundException:没有找到能够将[org.springframework.data.mongodb.core.geo.GeoJsonPoint]类型转换为[org.bson.Document]类型的转换器 在org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:321) 在org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:194) 在org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:174) 在org.springframework.data.mongodb.core.convert.MappingMongoConverter.getPotentiallyConvertedSimpleWrite(MappingMongoConverter.java:849)处 在org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeSimpleInternal(MappingMongoConverter.java:829) 在org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeProperties(MappingMongoConverter.java:488) 在org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:462) 在org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:436) 在org.springframework.data.mongodb.core.convert.MappingMongoConverter.write(MappingMongoConverter.java:391) 在org.springframework.data.mongodb.core.convert.MappingMongoConverter.write(MappingMongoConverter.java:86) 在org.springframework.data.mongodb.core.MongoTemplate.toDocument(MongoTemplate.java:1070) 在org.springframework.data.mongodb.core.MongoTemplate.doInsert(MongoTemplate.java:1048) 在org.springframework.data.mongodb.core.MongoTemplate.insert(MongoTemplate.java:988) 在org.springframework.data.mongodb.repository.support.SimpleMongoRepository.save(SimpleMongoRepository.java:80) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处 在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:498) 在org.springframework.data.repository.core.support.RepositoryComposition $ RepositoryFragments.invoke(RepositoryComposition.java:377) 在org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200) 在org.springframework.data.repository.core.support.RepositoryFactorySupport $ ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:629) 在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) 在org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:593) 在org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:578) 在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) 在org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59) 在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) 在org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) 在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) 在org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) 在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) 在org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) 在com.sun.proxy。$ Proxy127.save(未知来源) 在com.gt.ffm.restful.Application.run(Application.java:94) 在org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:797) ...还有11个