我試圖跟着new Cineasts應用程序與SDN 4.0.0.M1和SpringBoot學習Spring和Neo4j,但是當我嘗試訪問電影url時出現錯誤 curl http://localhost:8080/moviesMappingException:將GraphModel映射到實例的錯誤
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> {
}
的MovieController
@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
,當我去到本地主機:8080我可以看到JSON響應
{
"_links" : {
"movies" : {
"href" : "http://localhost:8080/movies"
},
"profile" : {
"href" : "http://localhost:8080/alps"
}
}
,但它不能顯示我剛剛創建的電影或http://localhost:8080/movies/1記錄。任何想法解決這個問題或獲得更相關的消息?
謝謝!
請張貼您的電影控制器代碼。 – Luanne
添加了MovieController – user4569126