I am integrating Neo4j into my JHipster 8.5.0 / Spring Boot 3.3.0 application. I have configured a Neo4jConfig with a Driver bean, a Neo4jService to send Cypher statements, and a REST endpoint /api/neo4j/import that calls this service.
→ The REST endpoint returns 200 OK. → Neo4jService is initialized (driver injected). → But inside executeCypherStatements(), I never see the expected "Executing Cypher" logs. → Also, no Cypher statements appear in Neo4j.
I added catch blocks but no exception is thrown either. Neo4j Desktop is running, bolt://localhost:7687 is up, and the driver connects (driver initialized).
I am using the official neo4j-java-driver version 5.11.0 (not the Spring Boot starter).
→ Why is my service not executing the Cypher? → Is this a limitation of using neo4j-java-driver in JHipster / Spring Boot? → Do I need to switch to spring-boot-starter-data-neo4j to make it work properly?
1- ** I created a Neo4jConfig:**
@Configuration
public class Neo4jConfig {
@Value("${neo4j.uri}")
private String uri;
@Value("${neo4j.username}")
private String username;
@Value("${neo4j.password}")
private String password;
@Bean
public Driver neo4jDriver() {
return GraphDatabase.driver(uri, AuthTokens.basic(username, password));
}
}
2- ** I created a Neo4jService:**
@Service
public class Neo4jService {
private final Driver driver;
public Neo4jService(Driver driver) {
this.driver = driver;
System.out.println("Neo4jService initialized with driver: " + driver);
}
@PostConstruct
public void postConstruct() {
System.out.println("Neo4jService postConstruct - driver: " + driver);
}
public void executeCypherStatements(List<String> statements) {
try (Session session = driver.session()) {
System.out.println("Neo4jService → session opened"); // I added this
for (String stmt : statements) {
System.out.println("Executing Cypher: " + stmt);
session.run(stmt);
}
} catch (Exception e) {
System.out.println("Neo4jService ERROR → " + e.getMessage());
e.printStackTrace();
}
}
}
3- ** I created a REST controller:**
@RestController
@RequestMapping("/api/neo4j")
public class Neo4jImportResource {
private final Neo4jService neo4jService;
@Autowired
public Neo4jImportResource(Neo4jService neo4jService) {
this.neo4jService = neo4jService;
}
@PostMapping("/import")
public ResponseEntity<String> importGraph() {
List<String> statements = List.of(
"MERGE (a:TestNode {name: 'NodeA'})",
"MERGE (b:TestNode {name: 'NodeB'})",
"MERGE (a)-[:CONNECTED_TO]->(b)"
);
neo4jService.executeCypherStatements(statements);
return ResponseEntity.ok("Import done");
}
}
4- In my application-dev.yml I configured:
neo4j:
uri: bolt://localhost:7687
username: neo4j
password: mypassword
5- Result:
I can see in backend console:
Neo4jService initialized with driver: org.neo4j.driver.internal.InternalDriver@xxxx
Neo4jService postConstruct, driver: org.neo4j.driver.internal.InternalDriver@xxxx
When I POST /api/neo4j/import I get HTTP 200 OK.
BUT I do NOT see:
Neo4jService → session opened
Executing Cypher: ...
→ It seems that executeCypherStatements() is not really executing → or that driver.session() fails silently.
6- Context Neo4j Desktop is started, with base neo4j running on port 7687.
The driver does connect (since driver is initialized).
No exception printed in catch block → but nothing runs.
JHipster project (so I use Gradle and neo4j-java-driver 5.11.0, not spring-boot-starter-data-neo4j).
7- Question:
- Why is my Neo4jService.executeCypherStatements() apparently not running?
- Why does session.run() produce no log / no exception but also no Cypher in Neo4j?
- Is this a problem with neo4j-java-driver used inside JHipster / Spring Boot? Do I need spring-boot-starter-data-neo4j instead?
→ Any advice welcome, I just want to inject Cypher statements reliably from my REST controller.
Thanks in advance!