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"] 
}