我正在尝试使用带有 SDN 4.0.0.M1 和 SpringBoot 的新 Cineasts应用程序来学习 Spring 和 Neo4j,但是当我尝试使用 curl http://localhost:8080/movies访问电影 url 时出现错误
MappingException:将 GraphModel 映射到实例时出错
我实现了最低限度的工作,所以代码很简单,但我可能忘记了一些东西
电影课
@NodeEntity
public class Movie {
@GraphId
private Long nodeId;
private String id;
private String title;
public Movie() {
}
public Movie(String id, String title) {
this.id = id;
this.title = title;
}
}
关联的 MovieRepository 目前为空
public interface MovieRepository extends GraphRepository<Movie> {
}
电影控制器
@Autowired
private MovieRepository movieRepository;
@Autowired
private Session session;
@RequestMapping(value = "/movies/{id}", method = RequestMethod.GET, headers = "Accept=application/json")
public
@ResponseBody
Movie getMovie(@PathVariable String id) {
return IteratorUtil.firstOrNull(findMovieByProperty("id", id));
}
public Iterable<Movie> findMovieByProperty(String propertyName, Object propertyValue) {
return session.loadByProperty(Movie.class, new Property(propertyName, propertyValue));
}
和具有数据库连接的主类
@SpringBootApplication
@EnableNeo4jRepositories("cineasts.repository")
@EnableTransactionManagement
public class CineastsApplication extends Neo4jConfiguration {
public static final int NEO4J_PORT = 7474;
@Bean
public Neo4jServer neo4jServer() {
return new RemoteServer("http://localhost:" + NEO4J_PORT);
}
@Override
public SessionFactory getSessionFactory() {
return new SessionFactory("org.neo4j.cineasts.domain");
}
@Override
@Bean
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public Session getSession() throws Exception {
return super.getSession();
}
public static void main(String[] args) {
SpringApplication.run(CineastsApplication.class, args);
}
}
我启动了 Neo4j 并使用 Neo4j 浏览器添加了一条记录
CREATE (m:Movie {id:1, name:'The Matrix'}) return m
当我去 localhost:8080 我可以看到 json 响应
{
"_links" : {
"movies" : {
"href" : "http://localhost:8080/movies"
},
"profile" : {
"href" : "http://localhost:8080/alps"
}
}
但它无法显示我刚刚创建的电影或http://localhost:8080/movies/1记录。有什么想法可以解决这个问题或获得更相关的信息吗?
谢谢!