我是 spring data 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
这正常吗?
这是我的 pom.xml
最佳答案
从 Spring Data Neo4j 5.x 开始,您应该扩展 Neo4jRepository
而不是 GraphRepository
。
GraphRepository
曾经出现在旧版本中。您依赖于 spring-boot 2.0.0.M7
,它间接依赖于 SDN 5。
如果您的 IDE 能够识别 GraphRepository
,那么您的项目设置中还有其他问题。
关于java - Spring Data Neo4j 图形存储库不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48009639/