【问题标题】:Spring Data Neo4j "No property get found for type" exceptionSpring Data Neo4j“找不到类型的属性”异常
【发布时间】:2013-02-24 09:14:41
【问题描述】:

我正在尝试将现有项目转换为使用 Spring Data 和 Neo4j,但遇到了一些问题。当我尝试构建项目时,出现以下异常:

[etc. ...]
Caused by: 
org.springframework.data.mapping.PropertyReferenceException: No property get found for type com.myproject.models.SuperNode
    at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:75)
[... etc.]

我似乎找不到任何关于我为什么会收到该错误的好信息,而且我不确定到底是什么原因造成的。

这是 SuperNode 类的大部分内容:

@NodeEntity
public class SuperNode extends AbstractMapValues {

    @GraphId
    private Long superNodeId;

    @NotNull
    private boolean superNodeFullyGenerated = false;

    private BaseLandType likelyLandType;

    private BaseLandType unlikelyLandType;

[methods and such]
}

它源自 AbstractMapValues 类:

@NodeEntity
public abstract class AbstractMapValues implements Comparable<AbstractMapValues> {

    @GraphId
    public Long id;

    @Range(min = 0, max = MAX_MAP_INT)
    private int xCoor;

    @Range(min = 0, max = MAX_MAP_INT)
    private int yCoor;

    //set only when x and y are set
    @Indexed(indexType = IndexType.POINT)
    private String wkt;

    @Range(min = BASIC_MIN, max = BASIC_MAX)
    private int percipitation;

    @Range(min = -1, max = BASIC_MAX)
    private int topography;

    @Range(min = BASIC_MIN, max = BASIC_MAX)
    private int seaLevel;

 [more int fields, but you get the picture]
 }

如您所见,这些用于表示地图中的点。我的项目中有一个 Neo4j 空间依赖项,这应该允许我使用 IndexType.POINT。

然后我有 SuperNode 的存储库。我有我的基本 CRUD 类型存储库接口,一个由基本存储库实现的自定义接口,这样我就可以实现自定义接口并写出需要使用 Neo4j 空间库的 get 方法.

基本回购:

public interface SuperNodeRepo extends CRUDRepository<SuperNode>, SpatialRepository<SuperNode>, SuperNodeRepoCustom {

}

自定义界面:

@NoRepositoryBean
public interface SuperNodeRepoCustom {

    public SuperNode getSuperNode(int xCoorSuperNode, int yCoorSuperNode) ;

    public List<SuperNode> getSuperNodes(int xmax, int xmin, int ymax, int ymin) ;

}

自定义实现(如您所见,目前不完整):

公共类 SuperNodeRepoCustomImpl 实现 SuperNodeRepoCustom {

public SuperNode getSuperNode(int xCoorSuperNode, int yCoorSuperNode) {
    return null;
}

public List<SuperNode> getSuperNodes(int xmax, int xmin, int ymax, int ymin) {
    return null;
}

}

我尝试将@Indexed 直接添加到超节点中的新字段,但这无济于事。我已经尝试过没有扩展spatialRepo。

当我在没有扩展我的自定义界面的情况下尝试它时,我得到一个不同的错误:

No matching bean of type [com.orclands.game.models.SuperNode] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

但我仍然不知道为什么会这样。所以最后,我有两个问题。 A. 我的自定义接口实现有什么问题,B. 除此之外还有什么问题!

任何帮助将不胜感激!

【问题讨论】:

  • 您的层次结构中应该只有一个@GraphId 注释。
  • 你有项目在 github 或其他地方看看吗?
  • 好吧,我删除了额外的@GraphId,但我仍然收到“No matching bean of type [com.orclands.game.models.SuperNode]”错误。恐怕我只在私人存储库中拥有它,因为它是一个个人项目。如果我遗漏了什么,我可以提供更多信息。
  • 我在 AbstractMapValues 层次结构中确实有一些其他类被注释为@NodeEntity,但没有任何其他注释。不过,这对获取有关 SuperNode 的错误应该没有影响,对吧?
  • 真的很抱歉,我没有发布应有的信息!我在服务层方法中有一个杂散的 @Autowired 注释,它试图将 SuperNode 自动装配到方法中,就好像它是一个 setter 一样(因为 SuperNode 实体是该方法的参数)。

标签: java spring neo4j spring-data-neo4j


【解决方案1】:
**@Repository**
public interface SuperNodeRepo extends CRUDRepository<SuperNode>, SpatialRepository<SuperNode>, SuperNodeRepoCustom {

}

【讨论】:

    猜你喜欢
    • 2013-11-04
    • 1970-01-01
    • 2013-06-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-17
    • 1970-01-01
    • 1970-01-01
    • 2012-02-17
    相关资源
    最近更新 更多