@@ -3554,7 +3554,7 @@ considered. A typical entity class resembles the following example:
3554
3554
3555
3555
public City(String name, String state) {
3556
3556
this.name = name;
3557
- this.country = country ;
3557
+ this.state = state ;
3558
3558
}
3559
3559
3560
3560
public String getName() {
@@ -3606,7 +3606,7 @@ The following example shows a typical Spring Data repository interface definitio
3606
3606
3607
3607
Page<City> findAll(Pageable pageable);
3608
3608
3609
- City findByNameAndCountryAllIgnoringCase (String name, String country );
3609
+ City findByNameAndStateAllIgnoringCase (String name, String state );
3610
3610
3611
3611
}
3612
3612
----
@@ -4006,7 +4006,7 @@ in the following example:
4006
4006
4007
4007
Page<City> findAll(Pageable pageable);
4008
4008
4009
- City findByNameAndCountryAllIgnoringCase (String name, String country );
4009
+ City findByNameAndStateAllIgnoringCase (String name, String state );
4010
4010
4011
4011
}
4012
4012
----
@@ -4045,75 +4045,82 @@ the Mongo instance's configuration and logging routing.
4045
4045
[[boot-features-neo4j]]
4046
4046
=== Neo4j
4047
4047
http://neo4j.com/[Neo4j] is an open-source NoSQL graph database that uses a rich data
4048
- model of nodes related by first class relationships, which is better suited for connected
4049
- big data than traditional rdbms approaches. Spring Boot offers several conveniences for
4048
+ model of nodes connected by first class relationships, which is better suited for connected
4049
+ big data than traditional RDBMS approaches. Spring Boot offers several conveniences for
4050
4050
working with Neo4j, including the `spring-boot-starter-data-neo4j` "`Starter`".
4051
4051
4052
4052
4053
4053
4054
4054
[[boot-features-connecting-to-neo4j]]
4055
4055
==== Connecting to a Neo4j Database
4056
- You can inject an auto-configured `Neo4jSession`, `Session`, or `Neo4jOperations`
4057
- instance as you would any other Spring Bean. By default, the instance tries to connect to
4058
- a Neo4j server at `localhost:7474`. The following example shows how to inject a Neo4j
4059
- bean:
4056
+ To access a Neo4j server, you can inject an auto-configured `org.neo4j.ogm.session.Session`.
4057
+ By default, the instance tries to connect to a Neo4j server at `localhost:7687` via the Bolt
4058
+ protocol. The following example shows how to inject a Neo4j session:
4060
4059
4061
4060
[source,java,indent=0]
4062
4061
----
4063
4062
@Component
4064
4063
public class MyBean {
4065
4064
4066
- private final Neo4jTemplate neo4jTemplate ;
4065
+ private final Session session ;
4067
4066
4068
4067
@Autowired
4069
- public MyBean(Neo4jTemplate neo4jTemplate ) {
4070
- this.neo4jTemplate = neo4jTemplate ;
4068
+ public MyBean(Session session ) {
4069
+ this.session = session ;
4071
4070
}
4072
4071
4073
4072
// ...
4074
4073
4075
4074
}
4076
4075
----
4077
4076
4078
- You can take full control of the configuration by adding a
4079
- `org.neo4j.ogm.config.Configuration` `@Bean` of your own. Also, adding a `@Bean` of type
4080
- `Neo4jOperations` disables the auto-configuration.
4081
-
4082
- You can configure the user and credentials to use by setting the `spring.data.neo4j.*`
4077
+ You can configure the uri and credentials to use by setting the `spring.data.neo4j.*`
4083
4078
properties, as shown in the following example:
4084
4079
4085
4080
[source,properties,indent=0]
4086
4081
----
4087
- spring.data.neo4j.uri=http ://my-server:7474
4082
+ spring.data.neo4j.uri=bolt ://my-server:7687
4088
4083
spring.data.neo4j.username=neo4j
4089
4084
spring.data.neo4j.password=secret
4090
4085
----
4091
4086
4087
+ You can take full control over the session creation by adding a
4088
+ `org.neo4j.ogm.config.Configuration` `@Bean`. To completely disable the auto-configuration
4089
+ provided by the "`Starter`" , add a `@Bean` of type `org.neo4j.ogm.session.SessionFactory`.
4090
+
4092
4091
4093
4092
4094
4093
[[boot-features-connecting-to-neo4j-embedded]]
4095
4094
==== Using the Embedded Mode
4096
4095
4097
4096
If you add `org.neo4j:neo4j-ogm-embedded-driver` to the dependencies of your application,
4098
4097
Spring Boot automatically configures an in-process embedded instance of Neo4j that does
4099
- not persist any data when your application shuts down. You can explicitly disable that
4100
- mode by setting `spring.data.neo4j.embedded.enabled=false`. You can also enable
4101
- persistence for the embedded mode by providing a path to a database file, as shown in the
4102
- following example:
4098
+ not persist any data when your application shuts down.
4103
4099
4104
- ----
4105
- spring.data.neo4j.uri=file://var/tmp/graph.db
4106
- ----
4100
+ [NOTE]
4101
+ ====
4102
+ As the embedded Neo4j OGM driver does not provide the Neo4j kernel itself, you have
4103
+ to declare `org.neo4j:neo4j` as dependency yourself. Refer to
4104
+ https://neo4j.com/docs/ogm-manual/current/reference/#reference:getting-started[the
4105
+ Neo4j OGM documentation] for list of compatible versions.
4106
+ ====
4107
+
4108
+ The embedded driver takes precedence over the other drivers when there are multiple
4109
+ drivers on the classpath. You can explicitly disable the embedded mode by setting
4110
+ `spring.data.neo4j.embedded.enabled=false`.
4111
+
4112
+ <<boot-features-testing-spring-boot-applications-testing-autoconfigured-neo4j-test,Data Neo4j Tests>>
4113
+ automatically make use of an embedded Neo4j instance if the embedded driver and Neo4j
4114
+ kernel are on the classpath as described above.
4107
4115
4108
4116
[NOTE]
4109
4117
====
4110
- The Neo4j OGM embedded driver does not provide the Neo4j kernel. Users are expected to
4111
- provide this dependency manually. See
4112
- http://neo4j.com/docs/ogm-manual/current/reference/#reference:getting-started[the
4113
- documentation] for more details.
4118
+ You can enable persistence for the embedded mode by providing a path to a database file
4119
+ in your configuration like this: `spring.data.neo4j.uri=file://var/tmp/graph.db`.
4114
4120
====
4115
4121
4116
4122
4123
+
4117
4124
[[boot-features-neo4j-ogm-session]]
4118
4125
==== Neo4jSession
4119
4126
@@ -4133,44 +4140,34 @@ pattern). If you do not want this behavior, add the following line to your
4133
4140
==== Spring Data Neo4j Repositories
4134
4141
Spring Data includes repository support for Neo4j.
4135
4142
4136
- In fact, both Spring Data JPA and Spring Data Neo4j share the same common infrastructure.
4137
- You could take the JPA example from earlier and, assuming that `City` is now a Neo4j OGM
4138
- `@NodeEntity` rather than a JPA `@Entity`, it works in the same way.
4139
-
4140
- TIP: You can customize entity scanning locations by using the `@EntityScan` annotation.
4141
-
4142
- To enable repository support (and optionally support for `@Transactional`), add the
4143
- following two annotations to your Spring configuration:
4144
-
4145
- [source,java,indent=0]
4146
- ----
4147
- @EnableNeo4jRepositories(basePackages = "com.example.myapp.repository")
4148
- @EnableTransactionManagement
4149
- ----
4150
-
4151
- ==== Repository Example
4152
-
4153
- The following example shows an interface definition for a Neo4j repository:
4143
+ Spring Data Neo4j shares the common infrastructure with Spring Data JPA as many other
4144
+ Spring Data modules do. You could take the JPA example from earlier and define
4145
+ `City` as Neo4j OGM `@NodeEntity` rather than JPA `@Entity` and the repository
4146
+ abstraction works in the same way, as shown in the following example:
4154
4147
4155
4148
[source,java,indent=0]
4156
4149
----
4157
4150
package com.example.myapp.domain;
4158
4151
4159
- import org.springframework.data.domain.*;
4160
- import org.springframework.data.repository.*;
4152
+ import java.util.Optional;
4161
4153
4162
- public interface CityRepository extends GraphRepository<City> {
4154
+ import org.springframework.data.neo4j.repository.*;
4163
4155
4164
- Page <City> findAll(Pageable pageable);
4156
+ public interface CityRepository extends Neo4jRepository <City, Long> {
4165
4157
4166
- City findByNameAndCountry (String name, String country );
4158
+ Optional< City> findOneByNameAndState (String name, String state );
4167
4159
4168
4160
}
4169
4161
----
4170
4162
4171
- TIP: For complete details of Spring Data Neo4j, including its rich object mapping
4172
- technologies, refer to the https://projects.spring.io/spring-data-neo4j/[reference
4173
- documentation].
4163
+ The `spring-boot-starter-data-neo4j` "`Starter`" enables the repository support as well
4164
+ as transaction management. You can customize the locations to look for repositories and
4165
+ entities by using `@EnableNeo4jRepositories` and `@EntityScan` respectively on a
4166
+ `@Configuration`-bean.
4167
+
4168
+ TIP: For complete details of Spring Data Neo4j, including its object mapping
4169
+ technologies, refer to the https://projects.spring.io/spring-data-neo4j/[project page] and
4170
+ the reference documentation.
4174
4171
4175
4172
4176
4173
0 commit comments