Skip to content

Commit bc99fa6

Browse files
committed
Merge pull request #14548 from michael-simons:fix-neo4j-doc
* pr/14548: Polish "Fix and improve Neo4j related documentation" Fix and improve Neo4j related documentation
2 parents aeca6d4 + 5506d97 commit bc99fa6

File tree

1 file changed

+53
-56
lines changed

1 file changed

+53
-56
lines changed

spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 53 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3554,7 +3554,7 @@ considered. A typical entity class resembles the following example:
35543554
35553555
public City(String name, String state) {
35563556
this.name = name;
3557-
this.country = country;
3557+
this.state = state;
35583558
}
35593559
35603560
public String getName() {
@@ -3606,7 +3606,7 @@ The following example shows a typical Spring Data repository interface definitio
36063606
36073607
Page<City> findAll(Pageable pageable);
36083608
3609-
City findByNameAndCountryAllIgnoringCase(String name, String country);
3609+
City findByNameAndStateAllIgnoringCase(String name, String state);
36103610
36113611
}
36123612
----
@@ -4006,7 +4006,7 @@ in the following example:
40064006
40074007
Page<City> findAll(Pageable pageable);
40084008
4009-
City findByNameAndCountryAllIgnoringCase(String name, String country);
4009+
City findByNameAndStateAllIgnoringCase(String name, String state);
40104010
40114011
}
40124012
----
@@ -4045,78 +4045,85 @@ the Mongo instance's configuration and logging routing.
40454045
[[boot-features-neo4j]]
40464046
=== Neo4j
40474047
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
4050-
working with Neo4j, including the `spring-boot-starter-data-neo4j` "`Starter`".
4048+
model of nodes connected by first class relationships, which is better suited for
4049+
connected big data than traditional RDBMS approaches. Spring Boot offers several
4050+
conveniences for working with Neo4j, including the `spring-boot-starter-data-neo4j`
4051+
"`Starter`".
40514052

40524053

40534054

40544055
[[boot-features-connecting-to-neo4j]]
40554056
==== 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:
4057+
To access a Neo4j server, you can inject an auto-configured
4058+
`org.neo4j.ogm.session.Session`. By default, the instance tries to connect to a Neo4j
4059+
server at `localhost:7687` using the Bolt protocol. The following example shows how to
4060+
inject a Neo4j `Session`:
40604061

40614062
[source,java,indent=0]
40624063
----
40634064
@Component
40644065
public class MyBean {
40654066
4066-
private final Neo4jTemplate neo4jTemplate;
4067+
private final Session session;
40674068
40684069
@Autowired
4069-
public MyBean(Neo4jTemplate neo4jTemplate) {
4070-
this.neo4jTemplate = neo4jTemplate;
4070+
public MyBean(Session session) {
4071+
this.session = session;
40714072
}
40724073
40734074
// ...
40744075
40754076
}
40764077
----
40774078

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.*`
4079+
You can configure the uri and credentials to use by setting the `spring.data.neo4j.*`
40834080
properties, as shown in the following example:
40844081

40854082
[source,properties,indent=0]
40864083
----
4087-
spring.data.neo4j.uri=http://my-server:7474
4084+
spring.data.neo4j.uri=bolt://my-server:7687
40884085
spring.data.neo4j.username=neo4j
40894086
spring.data.neo4j.password=secret
40904087
----
40914088

4089+
You can take full control over the session creation by adding a
4090+
`org.neo4j.ogm.config.Configuration` `@Bean`. Also, adding a `@Bean` of type
4091+
`SessionFactory` disables the auto-configuration and gives you full control.
4092+
40924093

40934094

40944095
[[boot-features-connecting-to-neo4j-embedded]]
40954096
==== Using the Embedded Mode
4096-
40974097
If you add `org.neo4j:neo4j-ogm-embedded-driver` to the dependencies of your application,
40984098
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:
4099+
not persist any data when your application shuts down.
41034100

4104-
----
4105-
spring.data.neo4j.uri=file://var/tmp/graph.db
4106-
----
4101+
[NOTE]
4102+
====
4103+
As the embedded Neo4j OGM driver does not provide the Neo4j kernel itself, you have
4104+
to declare `org.neo4j:neo4j` as dependency yourself. Refer to
4105+
https://neo4j.com/docs/ogm-manual/current/reference/#reference:getting-started[the
4106+
Neo4j OGM documentation] for a list of compatible versions.
4107+
====
4108+
4109+
The embedded driver takes precedence over the other drivers when there are multiple
4110+
drivers on the classpath. You can explicitly disable the embedded mode by setting
4111+
`spring.data.neo4j.embedded.enabled=false`.
4112+
4113+
<<boot-features-testing-spring-boot-applications-testing-autoconfigured-neo4j-test,Data Neo4j Tests>>
4114+
automatically make use of an embedded Neo4j instance if the embedded driver and Neo4j
4115+
kernel are on the classpath as described above.
41074116

41084117
[NOTE]
41094118
====
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.
4119+
You can enable persistence for the embedded mode by providing a path to a database file
4120+
in your configuration, e.g. `spring.data.neo4j.uri=file://var/tmp/graph.db`.
41144121
====
41154122

41164123

4124+
41174125
[[boot-features-neo4j-ogm-session]]
41184126
==== Neo4jSession
4119-
41204127
By default, if you are running a web application, the session is bound to the thread for
41214128
the entire processing of the request (that is, it uses the "Open Session in View"
41224129
pattern). If you do not want this behavior, add the following line to your
@@ -4133,42 +4140,32 @@ pattern). If you do not want this behavior, add the following line to your
41334140
==== Spring Data Neo4j Repositories
41344141
Spring Data includes repository support for Neo4j.
41354142

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:
41544147

41554148
[source,java,indent=0]
41564149
----
41574150
package com.example.myapp.domain;
41584151
4159-
import org.springframework.data.domain.*;
4160-
import org.springframework.data.repository.*;
4152+
import java.util.Optional;
41614153
4162-
public interface CityRepository extends GraphRepository<City> {
4154+
import org.springframework.data.neo4j.repository.*;
41634155
4164-
Page<City> findAll(Pageable pageable);
4156+
public interface CityRepository extends Neo4jRepository<City, Long> {
41654157
4166-
City findByNameAndCountry(String name, String country);
4158+
Optional<City> findOneByNameAndState(String name, String state);
41674159
41684160
}
41694161
----
41704162

4171-
TIP: For complete details of Spring Data Neo4j, including its rich object mapping
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
41724169
technologies, refer to the https://projects.spring.io/spring-data-neo4j/[reference
41734170
documentation].
41744171

0 commit comments

Comments
 (0)