spring数据neo4j图形库无法正常工作

问题描述 投票:0回答:1

我是Spring数据neo4j的新手,我在GraphRepository上有一些错误/问题。

我第一次有这个:

import guru.springframework.domain.Product;
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.data.neo4j.repository.Neo4jRepository;

public interface ProductRepository extends GraphRepository<Product> {

   Product findById(Long id);

    Product deleteById(Long id);
}

但是阅读一些文档,存储库已经提供了这样的方法。我不需要写它们。

这是我的产品域名

import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.NodeEntity;

import java.math.BigDecimal;


@NodeEntity
public class Product {

    @GraphId
    private Long id;
    private String description;
    private BigDecimal price;
    private String imageUrl;

    //getters and setters
}

这是我的测试课

   @Test
    public void testPersistence() {

        productRepository.deleteAll();
        //given
        Product product = new Product();
        product.setDescription(PRODUCT_DESCRIPTION);
        product.setImageUrl(IMAGE_URL);
        product.setPrice(BIG_DECIMAL_100);

        //when
        productRepository.save(product);

        //then
        Assert.assertNotNull(product.getId());

        //Product newProduct = productRepository.findById(product.getId()).orElse(null);


        Product newProduct = productRepository.findById(182L);

未检测到findById

error

这是正常的吗?

这是我的pom.xml

java spring spring-data-neo4j
1个回答
1
投票

从Spring Data Neo4j 5.x开始,你应该扩展Neo4jRepository而不是GraphRepository

GraphRepository曾经出现在旧版本中。你依赖于spring-boot 2.0.0.M7,它过渡依赖于SDN 5。

如果IDE识别GraphRepository,则项目设置中存在其他问题。

© www.soinside.com 2019 - 2024. All rights reserved.