首页 > 解决方案 > 当我想从 neo4j 获取一些数据时,我总是得到 null

问题描述

我想使用 Spring boot 从 Neo4j 获取一些数据,但我总是一无所获。换句话说,java似乎无法从neo4j数据库中获取数据。

代码按照neo4j Spring教程编写。https://neo4j.com/developer/spring-data-neo4j/

领域类

@NodeEntity
public class Weather {

    @Id
    @GeneratedValue
    private Long id;
    private String name;

    @Relationship(type = "HAS_INSTANCE")
    private List<Instance> instances = new ArrayList<>();

    @Relationship(type = "HAS_CHARACTERISTIC")
    private List<Characteristic> characteristics = new ArrayList<>();

    ...
}

存储库类

@RepositoryRestResource(collectionResourceRel = "weathers", path = "weathers")
public interface WeatherRepository extends Neo4jRepository<Weather, Long> {

}

服务等级

@Service
public class WeatherService {

    private final WeatherRepository weatherRepository;

    public WeatherService(WeatherRepository weatherRepository){
        this.weatherRepository = weatherRepository;
    }

    @Transactional(readOnly = true)
    public Iterable<Weather> findAll(){
        Iterable<Weather> result = weatherRepository.findAll();
        return result;
    }
}

控制器类

@RestController
@RequestMapping("/")
public class WeatherController {

    private final WeatherService weatherService;

    public WeatherController(WeatherService weatherService){
        this.weatherService = weatherService;
    }

    @GetMapping("/findAll")
    public Iterable<Weather> findAll(){
        return weatherService.findAll();
    }
}

并且用户名和密码配置在application.properties中。

有人可以帮我吗?谢谢!

标签: javaspringneo4j

解决方案


推荐阅读