Spring Boot 1.4.1 NullPointerException using SDN and neo4j OGM 2.0.5
using:
- spring boot 1.4.1;
- spring boot starter neo4j (from parent);
- spring data neo4j (from parent);
- neo4j-ogm-core 2.0.5.
project: https://github.com/TarekSaid/co.synergyspace/tree/master/posts-service
I'm getting the following exception:
java.lang.NullPointerException: null
at org.neo4j.ogm.session.delegates.LoadByTypeDelegate.resolvePropertyName(LoadByTypeDelegate.java:251) ~[neo4j-ogm-core-2.0.5.jar!/:na]
at org.neo4j.ogm.session.delegates.LoadByTypeDelegate.resolvePropertyAnnotations(LoadByTypeDelegate.java:224) ~[neo4j-ogm-core-2.0.5.jar!/:na]
at org.neo4j.ogm.session.delegates.LoadByTypeDelegate.loadAll(LoadByTypeDelegate.java:86) ~[neo4j-ogm-core-2.0.5.jar!/:na]
at org.neo4j.ogm.session.delegates.LoadByTypeDelegate.loadAll(LoadByTypeDelegate.java:157) ~[neo4j-ogm-core-2.0.5.jar!/:na]
when running a spring boot application (started with java -jar) and spring-data-neo4j. This is caused by the method scanClassFileEntry in org.neo4j.ogm.scanner.ClassPathScanner class.
Spring Boot puts the classes in BOOT-INF/classes, but the above method checks if the classpath is equal or starts with the packages to scan for domain objects:
for (String pathToScan : classPaths) {
// path = BOOT-INF/classes/co/synergyspace/posts but pathToScan = co/synergyspace/posts
if (path.equals(pathToScan) || path.startsWith(pathToScan.concat("/"))) {
LOGGER.debug("{} admits {} for entry: {}", pathToScan, path,name);
processor.process(inputStream);
break;
}
}
Therefore, my classes never get added to the session metadata, and when the resolvePropertyName tries to load the classInfo from session.metadata() for my entity BusinessEntity, classInfo is null, which throws the NullPointerException when trying to load the FieldInfo.
Duplicates #6709
The following change fixed it:
@EnableTransactionManagement
@EnableNeo4jRepositories({"co.synergyspace.posts.repositories", "BOOT-INF.classes.co.synergyspace.posts.repositories"})
@EntityScan({"co.synergyspace.posts.entities", "BOOT-INF.classes.co.synergyspace.posts.entities"})
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(AppConfig.class, args);
}
}
Thanks for following up