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
f2b2c085
Commit
f2b2c085
authored
Nov 25, 2014
by
Henryk Konsek
Committed by
Andy Wilkinson
Jul 16, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add auto-configuration support for Embedded MongoDB
See gh-2002
parent
4aace564
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
99 additions
and
0 deletions
+99
-0
pom.xml
spring-boot-autoconfigure/pom.xml
+5
-0
EmbedMongoAutoConfiguration.java
...boot/autoconfigure/mongo/EmbedMongoAutoConfiguration.java
+35
-0
spring.factories
...utoconfigure/src/main/resources/META-INF/spring.factories
+1
-0
EmbedMongoAutoConfigurationTests.java
...autoconfigure/mongo/EmbedMongoAutoConfigurationTests.java
+52
-0
pom.xml
spring-boot-dependencies/pom.xml
+6
-0
No files found.
spring-boot-autoconfigure/pom.xml
View file @
f2b2c085
...
@@ -25,6 +25,11 @@
...
@@ -25,6 +25,11 @@
<artifactId>
spring-boot
</artifactId>
<artifactId>
spring-boot
</artifactId>
</dependency>
</dependency>
<!-- Optional -->
<!-- Optional -->
<dependency>
<groupId>
de.flapdoodle.embed
</groupId>
<artifactId>
de.flapdoodle.embed.mongo
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<dependency>
<groupId>
com.atomikos
</groupId>
<groupId>
com.atomikos
</groupId>
<artifactId>
transactions-jdbc
</artifactId>
<artifactId>
transactions-jdbc
</artifactId>
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/EmbedMongoAutoConfiguration.java
0 → 100644
View file @
f2b2c085
package
org
.
springframework
.
boot
.
autoconfigure
.
mongo
;
import
com.mongodb.Mongo
;
import
de.flapdoodle.embed.mongo.MongodExecutable
;
import
de.flapdoodle.embed.mongo.MongodStarter
;
import
de.flapdoodle.embed.mongo.config.IMongodConfig
;
import
de.flapdoodle.embed.mongo.config.MongodConfigBuilder
;
import
de.flapdoodle.embed.mongo.config.Net
;
import
de.flapdoodle.embed.mongo.distribution.Version
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
java.io.IOException
;
import
static
de
.
flapdoodle
.
embed
.
process
.
runtime
.
Network
.
localhostIsIPv6
;
@Configuration
@ConditionalOnClass
({
Mongo
.
class
,
MongodStarter
.
class
})
public
class
EmbedMongoAutoConfiguration
{
@Autowired
private
MongoProperties
properties
;
@Bean
(
initMethod
=
"start"
,
destroyMethod
=
"stop"
)
public
MongodExecutable
embedMongoServer
()
throws
IOException
{
IMongodConfig
mongodConfig
=
new
MongodConfigBuilder
()
.
version
(
Version
.
Main
.
PRODUCTION
)
.
net
(
new
Net
(
properties
.
getPort
(),
localhostIsIPv6
()))
.
build
();
return
MongodStarter
.
getDefaultInstance
().
prepare
(
mongodConfig
);
}
}
spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories
View file @
f2b2c085
...
@@ -46,6 +46,7 @@ org.springframework.boot.autoconfigure.mail.MailSenderValidatorAutoConfiguration
...
@@ -46,6 +46,7 @@ org.springframework.boot.autoconfigure.mail.MailSenderValidatorAutoConfiguration
org.springframework.boot.autoconfigure.mobile.DeviceResolverAutoConfiguration,\
org.springframework.boot.autoconfigure.mobile.DeviceResolverAutoConfiguration,\
org.springframework.boot.autoconfigure.mobile.DeviceDelegatingViewResolverAutoConfiguration,\
org.springframework.boot.autoconfigure.mobile.DeviceDelegatingViewResolverAutoConfiguration,\
org.springframework.boot.autoconfigure.mobile.SitePreferenceAutoConfiguration,\
org.springframework.boot.autoconfigure.mobile.SitePreferenceAutoConfiguration,\
org.springframework.boot.autoconfigure.mongo.EmbedMongoAutoConfiguration,\
org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,\
org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,\
org.springframework.boot.autoconfigure.mongo.MongoDataAutoConfiguration,\
org.springframework.boot.autoconfigure.mongo.MongoDataAutoConfiguration,\
org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration,\
org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration,\
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/EmbedMongoAutoConfigurationTests.java
0 → 100644
View file @
f2b2c085
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
mongo
;
import
com.mongodb.CommandResult
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
springframework
.
boot
.
test
.
EnvironmentTestUtils
.
addEnvironment
;
import
static
org
.
springframework
.
util
.
SocketUtils
.
findAvailableTcpPort
;
public
class
EmbedMongoAutoConfigurationTests
{
private
AnnotationConfigApplicationContext
context
;
@After
public
void
close
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
@Test
public
void
shouldReturnVersionOfEmbeddedMongoServer
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
int
mongoPort
=
findAvailableTcpPort
();
addEnvironment
(
context
,
"spring.data.mongodb.host=localhost"
,
"spring.data.mongodb.port="
+
mongoPort
);
context
.
register
(
MongoAutoConfiguration
.
class
,
MongoDataAutoConfiguration
.
class
,
EmbedMongoAutoConfiguration
.
class
);
context
.
refresh
();
MongoTemplate
mongo
=
context
.
getBean
(
MongoTemplate
.
class
);
CommandResult
buildInfo
=
mongo
.
executeCommand
(
"{ buildInfo: 1 }"
);
assertEquals
(
"2.6.1"
,
buildInfo
.
getString
(
"version"
));
}
}
spring-boot-dependencies/pom.xml
View file @
f2b2c085
...
@@ -63,6 +63,7 @@
...
@@ -63,6 +63,7 @@
<derby.version>
10.11.1.1
</derby.version>
<derby.version>
10.11.1.1
</derby.version>
<dropwizard-metrics.version>
3.1.2
</dropwizard-metrics.version>
<dropwizard-metrics.version>
3.1.2
</dropwizard-metrics.version>
<ehcache.version>
2.10.0
</ehcache.version>
<ehcache.version>
2.10.0
</ehcache.version>
<embedmongo.version>
1.46.4
</embedmongo.version>
<flyway.version>
3.2.1
</flyway.version>
<flyway.version>
3.2.1
</flyway.version>
<freemarker.version>
2.3.22
</freemarker.version>
<freemarker.version>
2.3.22
</freemarker.version>
<elasticsearch.version>
1.5.2
</elasticsearch.version>
<elasticsearch.version>
1.5.2
</elasticsearch.version>
...
@@ -473,6 +474,11 @@
...
@@ -473,6 +474,11 @@
<artifactId>
logback-classic
</artifactId>
<artifactId>
logback-classic
</artifactId>
<version>
${logback.version}
</version>
<version>
${logback.version}
</version>
</dependency>
</dependency>
<dependency>
<groupId>
de.flapdoodle.embed
</groupId>
<artifactId>
de.flapdoodle.embed.mongo
</artifactId>
<version>
${embedmongo.version}
</version>
</dependency>
<dependency>
<dependency>
<groupId>
com.atomikos
</groupId>
<groupId>
com.atomikos
</groupId>
<artifactId>
transactions-jdbc
</artifactId>
<artifactId>
transactions-jdbc
</artifactId>
...
...
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