0

我正在創建我認爲是Spring中相當簡單的域模型。Spring Data Rest Neo4j:模板不能爲空或空

@NodeEntity 
class Dependency { 
    @GraphId 
    private Long id 
    String groupId 
    String artifactId 
    String version 

    @Fetch 
    @RelatedTo(type = "DEPENDS_ON", direction = OUTGOING) 
    Set<Dependency> dependencies = new HashSet<Dependency>() 
} 

注*以上內容是用groovy編寫的。

我還創建了一個後續的Repository(到目前爲止所有的教科書!)。

@RepositoryRestResource(collectionResourceRel = "dependency", path = "dependency") 
interface DependencyRepository extends PagingAndSortingRepository<Dependency, Long> { 
    List<Dependency> findByArtifactId(@Param("artifactId") String artifactId) 
} 

最後應用程序類....

@EnableNeo4jRepositories(basePackages = "io.byteshifter.depsgraph") 
@SpringBootApplication 
class Application extends Neo4jConfiguration { 

    public Application() { 
     setBasePackage("io.byteshifter.depsgraph") 
    } 

    @Bean(destroyMethod = "shutdown") 
    GraphDatabaseService graphDatabaseService() { 
     return new GraphDatabaseFactory().newEmbeddedDatabase("target/dependency.db") 
    } 

    public static void main(String[] args) throws Exception { 
     SpringApplication.run(Application, args) 
    } 
} 

現在,當我火了以下有效載荷在http://127.0.0.1:8080/dependency,它會創建的所有對象和關係我希望..

{ 
     "groupId": "group1", 
     "artifactId": "artifact1", 
     "version": "1.0", 
     "dependencies" : [ 
      {"groupId": "group2", "artifactId": "artifact2", "version": "2.0"}, 
      {"groupId": "group3", "artifactId": "artifact3", "version": "3.0"} 
     ] 
} 

取而代之,我得到..

{ 
    "cause": { 
    "cause": { 
     "cause": null, 
     "message": "Template must not be null or empty!" 
    }, 
    "message": "Template must not be null or empty! (through reference chain: io.byteshifter.depsgraph.domain.Dependency[\"dependencies\"]->java.util.LinkedHashSet[0])" 
    }, 
    "message": "Could not read JSON: Template must not be null or empty! (through reference chain: io.byteshifter.depsgraph.domain.Dependency[\"dependencies\"]->java.util.LinkedHashSet[0]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Template must not be null or empty! (through reference chain: io.byteshifter.depsgraph.domain.Dependency[\"dependencies\"]->java.util.LinkedHashSet[0])" 
} 

我毫不懷疑這是對我的缺乏理解。如果任何人都能幫助我指引正確的方向,那將會非常受歡迎。

回答

0

我的REST知識失敗了我。我應該一直使用URI來表示其他依賴關係。見下:

{ 
     "groupId": "group3", 
     "artifactId": "artifact3", 
     "version": "1.0", 
     "dependencies": ["http://127.0.0.1:8080/dependency/0", "http://127.0.0.1:8080/dependency/1", "http://127.0.0.1:8080/dependency/2"] 
}