Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
dc8685a9
Commit
dc8685a9
authored
Apr 06, 2016
by
Yogesh Lonkar
Committed by
Andy Wilkinson
Apr 07, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow embedded Mongo's storage to be configured via the environment
Closes gh-5617
parent
f9a86363
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
0 deletions
+71
-0
EmbeddedMongoAutoConfiguration.java
...figure/mongo/embedded/EmbeddedMongoAutoConfiguration.java
+4
-0
EmbeddedMongoProperties.java
...autoconfigure/mongo/embedded/EmbeddedMongoProperties.java
+42
-0
EmbeddedMongoAutoConfigurationTests.java
...e/mongo/embedded/EmbeddedMongoAutoConfigurationTests.java
+25
-0
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java
View file @
dc8685a9
...
...
@@ -125,6 +125,9 @@ public class EmbeddedMongoAutoConfiguration {
this
.
embeddedProperties
.
getFeatures
());
MongodConfigBuilder
builder
=
new
MongodConfigBuilder
()
.
version
(
featureAwareVersion
);
if
(
this
.
embeddedProperties
.
getStorage
()
!=
null
)
{
builder
.
replication
(
this
.
embeddedProperties
.
getStorage
());
}
if
(
getPort
()
>
0
)
{
builder
.
net
(
new
Net
(
getHost
().
getHostAddress
(),
getPort
(),
Network
.
localhostIsIPv6
()));
...
...
@@ -136,6 +139,7 @@ public class EmbeddedMongoAutoConfiguration {
return
builder
.
build
();
}
private
int
getPort
()
{
if
(
this
.
properties
.
getPort
()
==
null
)
{
return
MongoProperties
.
DEFAULT_PORT
;
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoProperties.java
View file @
dc8685a9
...
...
@@ -38,6 +38,8 @@ public class EmbeddedMongoProperties {
*/
private
String
version
=
"2.6.10"
;
private
Storage
storage
;
/**
* Comma-separated list of features to enable.
*/
...
...
@@ -60,4 +62,44 @@ public class EmbeddedMongoProperties {
this
.
features
=
features
;
}
public
Storage
getStorage
()
{
return
storage
;
}
public
void
setStorage
(
Storage
storage
)
{
this
.
storage
=
storage
;
}
public
static
class
Storage
extends
de
.
flapdoodle
.
embed
.
mongo
.
config
.
Storage
{
private
int
oplogSize
;
private
String
replSetName
;
private
String
databaseDir
;
public
int
getOplogSize
()
{
return
oplogSize
;
}
public
void
setOplogSize
(
int
oplogSize
)
{
this
.
oplogSize
=
oplogSize
;
}
public
String
getReplSetName
()
{
return
replSetName
;
}
public
void
setReplSetName
(
String
replSetName
)
{
this
.
replSetName
=
replSetName
;
}
public
String
getDatabaseDir
()
{
return
databaseDir
;
}
public
void
setDatabaseDir
(
String
databaseDir
)
{
this
.
databaseDir
=
databaseDir
;
}
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfigurationTests.java
View file @
dc8685a9
...
...
@@ -20,6 +20,7 @@ import java.net.UnknownHostException;
import
com.mongodb.CommandResult
;
import
com.mongodb.MongoClient
;
import
de.flapdoodle.embed.mongo.config.IMongodConfig
;
import
de.flapdoodle.embed.mongo.distribution.Feature
;
import
org.junit.After
;
import
org.junit.Test
;
...
...
@@ -112,6 +113,30 @@ public class EmbeddedMongoAutoConfigurationTests {
}
}
/**
* test dbpath configuration is loaded for mongodb process.
*/
@Test
public
void
dbPathIsAvailableInMongoConfiguration
()
{
ConfigurableApplicationContext
parent
=
new
AnnotationConfigApplicationContext
();
parent
.
refresh
();
try
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
.
setParent
(
parent
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.data.mongodb.port=0"
,
"spring.mongodb.embedded.storage.databaseDir=/Users/yogeshlo/db"
,
"spring.mongodb.embedded.storage.oplogSize=0"
);
this
.
context
.
register
(
EmbeddedMongoAutoConfiguration
.
class
,
MongoClientConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
IMongodConfig
mongoConfig
=
this
.
context
.
getBean
(
IMongodConfig
.
class
);
assertThat
(
mongoConfig
.
replication
().
getDatabaseDir
()).
isEqualTo
(
"/Users/yogeshlo/db"
);
}
finally
{
parent
.
close
();
}
}
private
void
assertVersionConfiguration
(
String
configuredVersion
,
String
expectedVersion
)
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment