由于定义的半径距离内的地理定位,我们需要找到一组对象。
我们尝试使用SpatialRepository类来使用Neo4 J空间库来实现方法“findWithinDistance”
使用索引类型POINT实现的已使用代码用于存储对象的经度和纬度:
@NodeEntity
@TypeAlias(value="MyObject")
public class MyObject{
@GraphId Long nodeId;
private String label;
private String description;
private Double lat;
private Double lon;
@Indexed(indexType = IndexType.POINT, indexName = "locations")
String wkt;
public void setLocation(float longitude, float latitude) {
this.wkt = String.format("POINT( %.2f %.2f )",longitude,longitude);
}
1)对于第一次运行,我们在neo4j数据库中创建对象没有任何问题(我们可以在neo4j中看到具有正确数据的对象) 对于第二次运行或创建一个新对象,我们说:具有相同名称但存在不同配置的索引!
java.lang.IllegalArgumentException: Index with the same name but different config exists!
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'objectRepositoryImpl': Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: org.springframework.data.neo4j.support.Neo4jTemplate fr.spart.is.neo4j.repository.ObjectRepositoryImpl.template;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'neo4jTemplate'
defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Instantiation of bean failed;
nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.Neo4jTemplate org.springframework.data.neo4j.config.Neo4jConfiguration.neo4jTemplate()
throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jMappingContext' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration:
Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Index with the same name but different config exists!
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
我必须实现findWithinDistance的方法的另一点:我们应该使用模板方法或Neo4j Cypher查询来搜索对象?
感谢您的帮助,
如果您需要精确的话,请不要犹豫
答案 0 :(得分:0)
你怎么运行这个?
您是否可以运行"纯粹的查询"变量首先导致索引被创建为lucene索引而不是空间索引?
您还可以使用neo4j模板删除索引(您可能必须注释掉要运行的修补程序的注释)