I have some logic which needs direct node access to neo4j but the rest of the app using Spring Data Neo4j (SDN) for simplicity. I thought to use a procedure with @Procedure, but I'm not sure how to use that procedure when using the neo4j embedded driver and SDN4. My configuration is very barebones as below:
@Configuration
@EnableNeo4jRepositories(basePackages = "recommender.repository")
@ComponentScan(basePackages = "recommender")
@EnableTransactionManagement
public class MyNeo4jConfiguration extends Neo4jConfiguration {
@Bean
public SessionFactory getSessionFactory() {
System.out.println("******* GET SESSION FACTORY!!!!");
// with domain entity base package(s)
return new SessionFactory("recommender.model");
}
// needed for session in view in web-applications
@Bean
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public Session getSession() throws Exception {
return super.getSession();
}
With a property file here:
#EmbeddedSetup
driver=org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver
#URI=file:/neo4j/data/graph.db
With that setup where can I place the class with @Procedure and @Context (for the db access) where SDN's implementation has access to it during war deployment.
SDN itself has no functionality to manage procedures for you. However, there is a way to access the underlying GraphDatabaseService:
EmbeddedDriver embeddedDriver = (EmbeddedDriver) Components.driver();
GraphDatabaseService databaseService = embeddedDriver.getGraphDatabaseService();
Using this, you can register your procedure
((GraphDatabaseAPI) getDatabase()).getDependencyResolver().resolveDependency(Procedures.class).register(YourProcedure.class);
However, not really sure if this works with your procedure class in the application classpath- worth trying though.
来源:https://stackoverflow.com/questions/38665465/deploy-a-procedure-to-neo4j-when-using-the-embedded-driver