<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>NucleiAdmin</artifactId>
<version>0.0.1-RELEASE</version>
<name>NucleiAdmin</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.2.RELEASE</version>
</parent>
<properties>
<start-class>nuclei.Application</start-class>
<java.version>1.7</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<tomcat.version>8.0.3</tomcat.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
</dependency>
<!-- spring-data-neo4j -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>4.0.0.RC2</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j-rest</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-cypher-compiler-2.1</artifactId>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<!-- test scoped beans only -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.wimpi</groupId>
<artifactId>telnetd-x</artifactId>
<version>2.1.1</version>
</dependency>
</dependencies>
<build>
<finalName>NucleiAdmin</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-libs-snapshot</id>
<name>Spring</name>
<url>http://repo.spring.io/libs-snapshot</url>
</repository>
<repository>
<id>neo4j</id>
<url>http://m2.neo4j.org/content/repositories/releases</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<packaging>war</packaging>
</project>
&#13;
package nuclei.repository;
import java.util.Map;
import nuclei.domain.Blueprint;
import nuclei.domain.IaaSTemplate;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.stereotype.Repository;
/**
* @author Karthikeyan
*
*/
@Repository
public interface BlueprintRepository extends GraphRepository<Blueprint>{
@Query("MATCH (Blueprint:Blueprint{isDeleted:'0'}) RETURN id(Blueprint) as id,Blueprint")
Iterable<Map<String,Object>> getTemplateBlueprints();
@Query("MATCH (n { name: {0} }) SET n.position = {1}")
Blueprint createNewTemplate(String name,String position);
}
&#13;
在我的项目中,我使用spring boot,neo4j和org.neo4j.ogm库在spring boot上集成neo4j。我能够实现GraphRepository的findone,findall和save方法。但是当使用我自己的查询插入值时,它显示错误。我无法找到问题的原因。我正在使用给定的查询`@Query(&#34; CREATE(n:Person {name:&#39; Andres&#39;,title:&#39; Developer&#39;})&#34;)
package nuclei.service;
import java.util.Map;
import nuclei.domain.Blueprint;
import nuclei.domain.IaaSTemplate;
import nuclei.repository.BlueprintRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.stereotype.Service;
/**
* @author Karthikeyan
*
*/
@Service("blueprintService")
public class BlueprintServiceImpl extends GenericService<Blueprint> implements
BlueprintService {
@Autowired
private BlueprintRepository blueprintRepository;
@Override
public GraphRepository<Blueprint> getRepository() {
return blueprintRepository;
}
@Override
public Iterable<Map<String, Object>> getTemplateBlueprints() {
return blueprintRepository.getTemplateBlueprints();
}
@Override
public Blueprint createNewTemplate(String name,String position){
return blueprintRepository.createNewTemplate(name,position);
}
}
&#13;
@RequestMapping(value = "/createBp", method = RequestMethod.POST)
public @ResponseBody BlueprintMessage createBP(
@FormDataParam("name") String name,
@FormDataParam("position") String position,
final HttpServletResponse response) {
ResponseStatus status = null;
// Long blueprintId = Long.parseLong(id);
Blueprint entity = null;
try {
entity = blueprintService.createNewTemplate(name, position);
//entity.setBlueprint(blueprint);
//entity.setIsDeleted("0");
super.create(entity);
status = new ResponseStatus(ResponseStatusCode.STATUS_OK, "SUCCESS");
} catch (Exception e) {
e.printStackTrace();
}
return new BlueprintMessage(status, entity);
}
&#13;
package nuclei.service;
import java.util.Map;
import nuclei.domain.Blueprint;
import nuclei.domain.IaaSTemplate;
/**
* @author Karthikeyan
*
*/
public interface BlueprintService extends MainService<Blueprint> {
Iterable<Map<String, Object>> getTemplateBlueprints();
Blueprint createNewTemplate(String name,String position);
}
&#13;
答案 0 :(得分:2)
请升级到SDN 4.0.0.RC2
以前的版本不允许通过query()修改Cypher语句。