pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.yml
spring:
data:
neo4j:
username: neo4j
password: 123456
uri: bolt://localhost:7687
auto-index: update
open-in-view: true
repositories:
enabled: true
embedded:
enabled: true
或 java 配置
package org.canaan.neo4j.config;
import org.neo4j.ogm.session.SessionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.annotation.EnableNeo4jAuditing;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
import org.springframework.data.neo4j.transaction.Neo4jTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
* @author Canaan
* @date 2019/7/11 9:16
*/
@Configuration
@EnableNeo4jRepositories(basePackages = "org.canaan.neo4j.graph")
@EnableTransactionManagement // 激活SDN隐式事务
@EnableNeo4jAuditing
public class Neo4jConfigurer {
@Value("${neo4j.uri}")
private String uri;
@Value("${neo4j.username}")
private String username;
@Value("${neo4j.password}")
private String password;
@Value("${neo4j.connection.pool.size}")
private Integer connectionPoolSize;
@Bean
public SessionFactory sessionFactory() {
return new SessionFactory(configuration(), "org.canaan.neo4j.graph");
}
@Bean
public org.neo4j.ogm.config.Configuration configuration() {
return new org.neo4j.ogm.config.Configuration.Builder()
.uri(uri)
.credentials(username, password)
.connectionPoolSize(connectionPoolSize)
.autoIndex("update")
.build();
}
@Bean
public Neo4jTransactionManager transactionManager() {
return new Neo4jTransactionManager(sessionFactory());
}
}
官方文档 - 开始:
https://docs.spring.io/spring-data/neo4j/docs/5.1.3.RELEASE/reference/html/#reference
配置文档:
配置:
https://docs.spring.io/spring-data/neo4j/docs/5.1.3.RELEASE/reference/html/#reference:configuration
集群:
https://docs.spring.io/spring-data/neo4j/docs/5.1.3.RELEASE/reference/html/#reference_clustering
高可用:
https://docs.spring.io/spring-data/neo4j/docs/5.1.3.RELEASE/reference/html/#reference:ha