我想使用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中。
有人可以帮我吗?谢谢!