| If you wish to use GORM for Neo4j outside of a Grails application you should declare the necessary dependencies, for example in Gradle: |
| |
| [source,groovy,subs="attributes"] |
| ---- |
| compile "org.grails:grails-datastore-gorm-neo4j:{version}" |
| ---- |
| |
| Then annotate your entities with the `grails.gorm.annotation.Entity` annotation and implement the link:../api/grails/neo4j/Node.html[Node] trait: |
| |
| [source,groovy] |
| ---- |
| import grails.neo4j.* |
| import grails.gorm.annotation.* |
| |
| @Entity |
| class Person implements Node<Person>{ |
| String name |
| } |
| ---- |
| |
| Then you need to place the bootstrap logic somewhere in your application which uses link:../api/org/grails/datastore/gorm/neo4j/Neo4jDatastore.html[Neo4jDatastore]: |
| |
| [source,groovy] |
| ---- |
| def datastore = new Neo4jDatastore(Person) |
| |
| println Person.count() |
| ---- |
| |
| For configuration you can either pass a map or an instance of the `org.springframework.core.env.PropertyResolver` interface: |
| |
| [source,groovy] |
| ---- |
| def datastore = new Neo4jDatastore(['grails.neo4j.url':'bolt://...'], Person) |
| |
| println Person.count() |
| ---- |
| |
| If you are using Spring with an existing `ApplicationContext` you can instead call use link:../api/grails/neo4j/bootstrap/Neo4jDataStoreSpringInitializer.html[Neo4jDataStoreSpringInitializer] and call `configureForBeanDefinitionRegistry` prior to refreshing the context. You can pass the Spring `Environment` object to the constructor for configuration: |
| |
| [source,groovy] |
| ---- |
| ApplicationContext myApplicationContext = ... |
| def initializer = new Neo4jDataStoreSpringInitializer(myApplicationContext.getEnvironment(), Person) |
| initializer.configureForBeanDefinitionRegistry(myApplicationContext) |
| |
| println Person.count() |
| ---- |