I have a Spring Boot project with the Spring Data Neo4J dependency. I have defined a few nodes, a relation and a repository. Now the application starts correctly, but when I send a request to an endpoint that executes a repository method (like save or findById), then it keeps telling me that the transactionTemplate is null. I am guessing this is a configuration issue, but I haven’t been able to find any helpful information online.
@SpringBootApplication
@EnableNeo4jRepositories(basePackages = {"api.data.neo4j"})
public class AgendaApplication {
public static void main(String[] args) {
SpringApplication.run(AgendaApplication.class, args);
}
}
@Data
@Node("Agenda")
@AllArgsConstructor
public class AgendaNode {
@Id
@GeneratedValue
private long id;
}
public interface AgendaRepository extends Neo4jRepository<AgendaNode, Long> {
}
AgendaNode agendaNode = new AgendaNode(1);
agendaRepository.save(agendaNode); // This is where it causes the error
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.NullPointerException: Cannot invoke "org.springframework.transaction.support.TransactionTemplate.execute(org.springframework.transaction.support.TransactionCallback)" because "this.transactionTemplate" is null] with root cause
I tried the AgendaApplication versions below, but they all kept giving me the issue that this.transactionTemplate is null.
@SpringBootApplication
@EnableTransactionManagement
@EnableNeo4jRepositories(basePackages = {"api.data.neo4j"})
public class AgendaApplication {
public static void main(String[] args) {
SpringApplication.run(AgendaApplication.class, args);
}
}
@SpringBootApplication
@EnableNeo4jRepositories(basePackages = {"api.data.neo4j"})
public class AgendaApplication {
public static void main(String[] args) {
SpringApplication.run(AgendaApplication.class, args);
}
@Bean
public TransactionTemplate transactionTemplate(PlatformTransactionManager transactionManager) {
return new TransactionTemplate(transactionManager);
}
}
I also tried using the ReactiveNeo4jRepository instead of the Neo4jRepository and I tried overwriting the save method in the repository, but that didn’t work either.
Can anyone help resolve my issue?
Justin Slijkhuis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.