Skip to content

Commit 7673177

Browse files
author
liaozihong
committed
添加集成neo4j
1 parent 888c3ae commit 7673177

File tree

7 files changed

+113
-1
lines changed

7 files changed

+113
-1
lines changed

SpringBoot-Neo4j/.gitignore

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
HELP.md
2+
.gradle
3+
build/
4+
!gradle/wrapper/gradle-wrapper.jar
5+
!**/src/main/**/build/
6+
!**/src/test/**/build/
7+
8+
### STS ###
9+
.apt_generated
10+
.classpath
11+
.factorypath
12+
.project
13+
.settings
14+
.springBeans
15+
.sts4-cache
16+
bin/
17+
!**/src/main/**/bin/
18+
!**/src/test/**/bin/
19+
20+
### IntelliJ IDEA ###
21+
.idea
22+
*.iws
23+
*.iml
24+
*.ipr
25+
out/
26+
!**/src/main/**/out/
27+
!**/src/test/**/out/
28+
29+
### NetBeans ###
30+
/nbproject/private/
31+
/nbbuild/
32+
/dist/
33+
/nbdist/
34+
/.nb-gradle/
35+
36+
### VS Code ###
37+
.vscode/

SpringBoot-Neo4j/build.gradle

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dependencies {
2+
compile project(':SpringBoot-Support')
3+
compile 'org.neo4j.driver:neo4j-java-driver:4.3.4'
4+
compile('org.springframework.boot:spring-boot-starter-data-neo4j')
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.dashuai.learning.neo4j;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
6+
7+
@SpringBootApplication
8+
public class Neo4jApplication {
9+
10+
public static void main(String[] args) {
11+
SpringApplication.run(Neo4jApplication.class, args);
12+
}
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.dashuai.learning.neo4j.connect;
2+
3+
import org.neo4j.driver.*;
4+
5+
import static org.neo4j.driver.Values.parameters;
6+
7+
public class Neo4jConnect implements AutoCloseable {
8+
private final Driver driver;
9+
10+
public Neo4jConnect( String uri, String user, String password )
11+
{
12+
driver = GraphDatabase.driver( uri, AuthTokens.basic( user, password ) );
13+
}
14+
15+
@Override
16+
public void close() throws Exception
17+
{
18+
driver.close();
19+
}
20+
21+
public void printGreeting( final String message )
22+
{
23+
try ( Session session = driver.session() )
24+
{
25+
String greeting = session.writeTransaction( new TransactionWork<String>()
26+
{
27+
@Override
28+
public String execute( Transaction tx )
29+
{
30+
Result result = tx.run( "CREATE (a:JAVA) " +
31+
"SET a.message = $message " +
32+
"RETURN a.message + ', from node ' + id(a)",
33+
parameters( "message", message ) );
34+
return result.single().get( 0 ).asString();
35+
}
36+
} );
37+
System.out.println( greeting );
38+
}
39+
}
40+
41+
public static void main( String... args ) throws Exception
42+
{
43+
try ( Neo4jConnect greeter = new Neo4jConnect( "bolt://localhost:7687", "neo4j", "123456" ) )
44+
{
45+
greeter.printGreeting( "hello, world neo4j" );
46+
}
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
spring.data.neo4j.uri=bolt://localhost:7687
2+
spring.data.neo4j.username=neo4j
3+
spring.data.neo4j.password=123456
4+
spring.data.neo4j.database=hello
5+
logging.level.org.springframework.data.neo4j=DEBUG
6+
spring.main.allow-bean-definition-overriding=true

SpringBoot-Support/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ dependencies {
99
compile('org.springframework.boot:spring-boot-starter-web')
1010
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
1111
compile 'ma.glasnost.orika:orika-core:1.5.2'
12+
1213
}

settings.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ rootProject.name = 'springboot'
77
//include(':SpringBoot-Mybatis-Plus')
88
//include(':SpringBoot-Mybatis-Mycat')
99
//include(':SpringBoot-Mybatis-Ehcache')
10-
include(':SpringBoot-Mybatis-Multisource')
10+
//include(':SpringBoot-Mybatis-Multisource')
1111
//include(':SpringBoot-Mysql-Master-Slave')
1212
//include(':SpringBoot-ActiveMq')
1313
//include(':SpringBoot-Nsq-Consumer')
@@ -45,6 +45,7 @@ include(':SpringBoot-Mybatis-Multisource')
4545
//include(':SpringBoot-Alibaba-Sentinel')
4646
//include(':SpringBoot-Mybatis-Freemarker')
4747
//include(':SpringBoot-Gecco-Reptile')
48+
include(':SpringBoot-Neo4j')
4849
include(':SpringBoot-Support')
4950
// spring-boot-starter-webflux模块与web冲突,如果web模块的类不能用,请注释下面的模块
5051
//include(':SpringBoot-WebFlux')

0 commit comments

Comments
 (0)