Skip to content

Commit a16a9fe

Browse files
jxblumchristophstrobl
authored andcommitted
Edit README to include complete steps for building from source.
Closes: #3833
1 parent 2f98a66 commit a16a9fe

File tree

1 file changed

+145
-13
lines changed

1 file changed

+145
-13
lines changed

README.adoc

+145-13
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ The Spring Data MongoDB project aims to provide a familiar and consistent Spring
88
The Spring Data MongoDB project provides integration with the MongoDB document database.
99
Key functional areas of Spring Data MongoDB are a POJO centric model for interacting with a MongoDB `+Document+` and easily writing a repository style data access layer.
1010

11+
[[code-of-conduct]]
1112
== Code of Conduct
1213

1314
This project is governed by the https://github.com/spring-projects/.github/blob/e3cc2ff230d8f1dca06535aa6b5a4a23815861d4/CODE_OF_CONDUCT.md[Spring Code of Conduct]. By participating, you are expected to uphold this code of conduct. Please report unacceptable behavior to [email protected].
1415

16+
[[getting-started]]
1517
== Getting Started
1618

1719
Here is a quick teaser of an application using Spring Data Repositories in Java:
@@ -59,6 +61,7 @@ class ApplicationConfig extends AbstractMongoClientConfiguration {
5961
}
6062
----
6163

64+
[[maven-configuration]]
6265
=== Maven configuration
6366

6467
Add the Maven dependency:
@@ -68,24 +71,25 @@ Add the Maven dependency:
6871
<dependency>
6972
<groupId>org.springframework.data</groupId>
7073
<artifactId>spring-data-mongodb</artifactId>
71-
<version>${version}.RELEASE</version>
74+
<version>${version}</version>
7275
</dependency>
7376
----
7477

75-
If you'd rather like the latest snapshots of the upcoming major version, use our Maven snapshot repository and declare the appropriate dependency version.
78+
If you'd rather like the latest snapshots of the upcoming major version, use our Maven snapshot repository
79+
and declare the appropriate dependency version.
7680

7781
[source,xml]
7882
----
7983
<dependency>
8084
<groupId>org.springframework.data</groupId>
8185
<artifactId>spring-data-mongodb</artifactId>
82-
<version>${version}.BUILD-SNAPSHOT</version>
86+
<version>${version}-SNAPSHOT</version>
8387
</dependency>
8488
8589
<repository>
86-
<id>spring-libs-snapshot</id>
90+
<id>spring-snapshot</id>
8791
<name>Spring Snapshot Repository</name>
88-
<url>https://repo.spring.io/libs-snapshot</url>
92+
<url>https://repo.spring.io/snapshot</url>
8993
</repository>
9094
----
9195

@@ -98,7 +102,7 @@ Some of the changes affect the initial setup configuration as well as compile/ru
98102

99103
.Changed XML Namespace Elements and Attributes:
100104
|===
101-
Element / Attribute | 2.x | 3.x
105+
| Element / Attribute | 2.x | 3.x
102106

103107
| `<mongo:mongo-client />`
104108
| Used to create a `com.mongodb.MongoClient`
@@ -116,7 +120,7 @@ Use `<mongo:client-settings cluster-hosts="..." />` instead
116120

117121
.Removed XML Namespace Elements and Attributes:
118122
|===
119-
Element / Attribute | Replacement in 3.x | Comment
123+
| Element / Attribute | Replacement in 3.x | Comment
120124

121125
| `<mongo:db-factory mongo-ref="..." />`
122126
| `<mongo:db-factory mongo-client-ref="..." />`
@@ -133,7 +137,7 @@ Element / Attribute | Replacement in 3.x | Comment
133137

134138
.New XML Namespace Elements and Attributes:
135139
|===
136-
Element | Comment
140+
| Element | Comment
137141

138142
| `<mongo:db-factory mongo-client-ref="..." />`
139143
| Replacement for `<mongo:db-factory mongo-ref="..." />`
@@ -153,7 +157,7 @@ Element | Comment
153157

154158
.Java API changes
155159
|===
156-
Type | Comment
160+
| Type | Comment
157161

158162
| `MongoClientFactoryBean`
159163
| Creates `com.mongodb.client.MongoClient` instead of `com.mongodb.MongoClient` +
@@ -174,7 +178,7 @@ Uses `MongoClientSettings` instead of `MongoClientOptions`.
174178

175179
.Removed Java API:
176180
|===
177-
2.x | Replacement in 3.x | Comment
181+
| 2.x | Replacement in 3.x | Comment
178182

179183
| `MongoClientOptionsFactoryBean`
180184
| `MongoClientSettingsFactoryBean`
@@ -226,6 +230,7 @@ static class Config extends AbstractMongoClientConfiguration {
226230
----
227231
====
228232

233+
[[getting-help]]
229234
== Getting Help
230235

231236
Having trouble with Spring Data? We’d love to help!
@@ -239,6 +244,7 @@ If you are just starting out with Spring, try one of the https://spring.io/guide
239244
You can also chat with the community on https://gitter.im/spring-projects/spring-data[Gitter].
240245
* Report bugs with Spring Data MongoDB at https://github.com/spring-projects/spring-data-mongodb/issues[github.com/spring-projects/spring-data-mongodb/issues].
241246

247+
[[reporting-issues]]
242248
== Reporting Issues
243249

244250
Spring Data uses Github as issue tracking system to record bugs and feature requests.
@@ -249,10 +255,135 @@ If you want to raise an issue, please follow the recommendations below:
249255
* Please provide as much information as possible with the issue report, we like to know the version of Spring Data that you are using, the JVM version, Stacktrace, etc.
250256
* If you need to paste code, or include a stack trace use https://guides.github.com/features/mastering-markdown/[Markdown] code fences +++```+++.
251257

258+
[[building-from-source]]
252259
== Building from Source
253260

254-
You don’t need to build from source to use Spring Data (binaries in https://repo.spring.io[repo.spring.io]), but if you want to try out the latest and greatest, Spring Data can be easily built with the https://github.com/takari/maven-wrapper[maven wrapper].
255-
You also need JDK 1.8.
261+
You do not need to build from source to use Spring Data. Binaries are available in https://repo.spring.io[repo.spring.io].
262+
and accessible from Maven using the Maven configuration noted <<maven-configuration,above>>.
263+
264+
NOTE: Configuration for Gradle is similar to Maven.
265+
266+
The best way to get started is by creating a Spring Boot project using MongoDB on https://start.spring.io[start.spring.io].
267+
Follow this https://start.spring.io/#type=maven-project&language=java&platformVersion=2.5.4&packaging=jar&jvmVersion=1.8&groupId=com.example&artifactId=demo&name=demo&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.demo&dependencies=data-mongodb[link]
268+
to build an imperative application and this https://start.spring.io/#type=maven-project&language=java&platformVersion=2.5.4&packaging=jar&jvmVersion=1.8&groupId=com.example&artifactId=demo&name=demo&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.demo&dependencies=data-mongodb-reactive[link]
269+
to build a reactive one.
270+
271+
However, if you want to try out the latest and greatest, Spring Data can be easily built with the https://github.com/takari/maven-wrapper[maven wrapper]
272+
and minimally JDK 8 (https://www.oracle.com/java/technologies/downloads/[JDK downloads]).
273+
274+
In order to build Spring Data MongoDB, first you will need to https://www.mongodb.com/try/download/community[download]
275+
and install a MongoDB distribution. Select "_On-premises (MongoDB locally)_", then "_MongoDB Community Server_"
276+
and in the page form, select the platform matching your system along with the version of MongoDB on which Spring Data
277+
MongoDB is based (https://github.com/spring-projects/spring-data-mongodb/blob/3.2.5/pom.xml#L30[for example]).
278+
279+
Once you have installed MongoDB, you need to start a MongoDB server. It is convenient to set an environment variable to
280+
your MongoDB installation (e.g. `MONGODB_HOME`).
281+
282+
To run the MongoDB server enter the following command from a command-line:
283+
284+
[source,bash]
285+
----
286+
$ $MONGODB_HOME/bin/mongod --dbpath $MONGODB_HOME/runtime/data --ipv6 --port 27017 --replSet rs0
287+
...
288+
{"t":{"$date":"2021-09-22T11:22:05.490-07:00"},"s":"I", "c":"NETWORK", "id":20113, "ctx":"LogicalSessionCacheReap",
289+
"msg":"Successfully connected to host","attr":{"connString":"127.0.0.1:27017","numOpenConns":1,"socketTimeoutSecs":0.0}}
290+
----
291+
292+
Once the MongoDB server starts up, you should see the message (`msg`), "_Successfully connected to host_".
293+
294+
Notice the `--dbpath` option to the `mongod` command. You can set this to anything you like, but in this case, we set
295+
the absolute path to a sub-directory (`runtime/data/`) under the MongoDB installation directory (in `$MONGODB_HOME`).
296+
You might have other sub-directories as well, such as `runtime/logs/` for instance, if you wish to write your logs to
297+
a file rather than standard out, using the `--logpath` option to the `mongod` command. In this way, all your "runtime"
298+
files for the MongoDB server are conveniently located in one place.
299+
300+
Next, you need to initialize the MongoDB replica set the first time the MongoDB server is started. Replicas are used by
301+
the Spring Data MongoDB transactional tests. This only needs to be done once after the initial start. If you restart
302+
your MongoDB server, you will need to initialize the replica set again. However, you can continue to use the same
303+
MongoDB server for multiple builds of Spring Data MongoDB.
304+
305+
To initialize the replica set, you must start a mongo client:
306+
307+
[source,bash]
308+
----
309+
$ $MONGODB_HOME/bin/mongo
310+
MongoDB server version: 4.4.8
311+
---
312+
The server generated these startup warnings when booting:
313+
2021-09-22T11:26:50.752-07:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
314+
2021-09-22T11:26:50.752-07:00: This server is bound to localhost. Remote systems will be unable to connect to this server. Start the server with --bind_ip <address> to specify which IP addresses it should serve responses from, or with --bind_ip_all to bind to all interfaces. If this behavior is desired, start the server with --bind_ip 127.0.0.1 to disable this warning
315+
2021-09-22T11:26:50.752-07:00: Soft rlimits too low
316+
2021-09-22T11:26:50.752-07:00: currentValue: 256
317+
2021-09-22T11:26:50.752-07:00: recommendedMinimum: 64000
318+
---
319+
---
320+
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
321+
metrics about your deployment (disk utilization, CPU, operation statistics, etc).
322+
323+
The monitoring data will be available on a MongoDB website with a unique URL accessible to you
324+
and anyone you share the URL with. MongoDB may use this information to make product
325+
improvements and to suggest MongoDB products and deployment options to you.
326+
327+
To enable free monitoring, run the following command: db.enableFreeMonitoring()
328+
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
329+
---
330+
rs0:PRIMARY>
331+
----
332+
333+
Then enter the following command:
334+
335+
[source,bash]
336+
----
337+
rs0:PRIMARY> rs.initiate({ _id: 'rs0', members: [ { _id: 0, host: '127.0.0.1:27017' } ] })
338+
{
339+
"operationTime" : Timestamp(1632335237, 1),
340+
"ok" : 0,
341+
"errmsg" : "already initialized",
342+
"code" : 23,
343+
"codeName" : "AlreadyInitialized",
344+
"$clusterTime" : {
345+
"clusterTime" : Timestamp(1632335237, 1),
346+
"signature" : {
347+
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
348+
"keyId" : NumberLong(0)
349+
}
350+
}
351+
}
352+
rs0:PRIMARY>
353+
----
354+
355+
Finally, you may need to adjust the `ulimit` on your UNIX-based system (for example, Linux or Mac OS X). Currently,
356+
the MongoDB client/server combination uses many Socket connections (which equate to file descriptors on a UNIX-based
357+
system) throughout the Spring Data MongoDB test suite lifecycle. You can inspect your current `ulimit` with
358+
the following command:
359+
360+
[source,bash]
361+
----
362+
$ ulimit -a
363+
core file size (blocks, -c) 0
364+
data seg size (kbytes, -d) unlimited
365+
file size (blocks, -f) unlimited
366+
max locked memory (kbytes, -l) unlimited
367+
max memory size (kbytes, -m) unlimited
368+
open files (-n) 256
369+
pipe size (512 bytes, -p) 1
370+
stack size (kbytes, -s) 8192
371+
cpu time (seconds, -t) unlimited
372+
max user processes (-u) 5568
373+
virtual memory (kbytes, -v) unlimited
374+
----
375+
376+
In this case, we are interested in the `ulimit` setting for "_open files_". As you can see above, this is set to 256.
377+
You will need to adjust this with the following command (we recommend 32768):
378+
379+
[source,bash]
380+
----
381+
$ ulimit -n 32768
382+
----
383+
384+
You can use `ulimit -a` again to verify the `ulimit` on "_open files_" was set appropriately.
385+
386+
Now you are ready to build Spring Data MongoDB. Simply enter the following `mvnw` (Maven Wrapper) command:
256387

257388
[source,bash]
258389
----
@@ -261,7 +392,8 @@ You also need JDK 1.8.
261392

262393
If you want to build with the regular `mvn` command, you will need https://maven.apache.org/run-maven/index.html[Maven v3.5.0 or above].
263394

264-
_Also see link:CONTRIBUTING.adoc[CONTRIBUTING.adoc] if you wish to submit pull requests, and in particular please sign the https://cla.pivotal.io/sign/spring[Contributor’s Agreement] before your first non-trivial change._
395+
_Also see link:CONTRIBUTING.adoc[CONTRIBUTING.adoc] if you wish to submit pull requests, and in particular, please sign
396+
the https://cla.pivotal.io/sign/spring[Contributor’s Agreement] before your first non-trivial change._
265397

266398
=== Building reference documentation
267399

0 commit comments

Comments
 (0)