@@ -0,0 +1,3283 @@
+package tk.hishopapp.configs;%0A%0Aimport com.mongodb.Mongo;%0Aimport com.mongodb.MongoClient;%0Aimport com.mongodb.MongoClientURI;%0Aimport de.flapdoodle.embed.mongo.Command;%0Aimport de.flapdoodle.embed.mongo.MongodExecutable;%0Aimport de.flapdoodle.embed.mongo.MongodProcess;%0Aimport de.flapdoodle.embed.mongo.MongodStarter;%0Aimport de.flapdoodle.embed.mongo.config.*;%0Aimport de.flapdoodle.embed.mongo.distribution.Version;%0Aimport de.flapdoodle.embed.process.config.IRuntimeConfig;%0Aimport de.flapdoodle.embed.process.extract.UserTempNaming;%0Aimport de.flapdoodle.embed.process.runtime.Network;%0Aimport org.springframework.beans.factory.annotation.Value;%0Aimport org.springframework.context.annotation.Bean;%0Aimport org.springframework.context.annotation.Configuration;%0Aimport org.springframework.context.annotation.Profile;%0Aimport org.springframework.core.Ordered;%0Aimport org.springframework.core.annotation.Order;%0Aimport org.springframework.data.mongodb.core.MongoOperations;%0Aimport org.springframework.data.mongodb.core.MongoTemplate;%0A%0Aimport java.io.IOException;%0A%0A/**%0A * Created by Nikita Bakaev, ya@nbakaev.ru on 2/9/2016.%0A * All Rights Reserved%0A */%0A@Configuration%0A@Order(Ordered.HIGHEST_PRECEDENCE)%0Apublic class MongoConfiguration %7B%0A%0A    @Value(%22$%7Bspring.data.mongodb.uri%7D%22)%0A    private String productionMongoUrl;%0A%0A    @Value(%22$%7Bmongodb.port%7D%22)%0A    private String developmentMongoDbPort;%0A%0A    @Value(%22$%7Bmongodb.database%7D%22)%0A    private String database;%0A%0A//    @Bean(destroyMethod = %22close%22)%0A    @Bean%0A    @Profile(%7B%22development%22%7D)%0A    public MongoOperations mongoEmbedded() throws IOException %7B%0A%0A        int port = Integer.parseInt(developmentMongoDbPort);%0A        Command command = Command.MongoD;%0A%0A//        MongodStarter starter = MongodStarter.getDefaultInstance();%0A%0A        IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()%0A                .defaults(command)%0A                .artifactStore(new ExtractedArtifactStoreBuilder()%0A                        .defaults(command)%0A                        .download(new DownloadConfigBuilder()%0A                                .defaultsForCommand(command).build())%0A                        .executableNaming(new UserTempNaming()))%0A                .build();%0A%0A        IMongodConfig mongodConfig = new MongodConfigBuilder()%0A                .version(Version.V3_2_0)%0A                .net(new Net(port, Network.localhostIsIPv6()))%0A                .build();%0A%0A//        MongodStarter runtime = MongodStarter.getInstance(runtimeConfig);%0A        MongodStarter runtime = MongodStarter.getDefaultInstance();%0A%0A%0A        MongodExecutable mongodExecutable = null;%0A        try%7B%0A            mongodExecutable = runtime.prepare(mongodConfig);%0A        %7Dcatch (Exception e)%7B%0A            mongodExecutable.getFile();%0A        %7D%0A        MongodProcess mongod = mongodExecutable.start();%0A%0A        MongoClient mongo = new MongoClient(%22localhost%22, port);%0A        MongoOperations mongoTemplate = new MongoTemplate(mongo, database);%0A        return mongoTemplate;%0A    %7D%0A%0A    @Profile(%7B%22production%22, %22default%22%7D)%0A    @Bean%0A    public MongoOperations mongoProduction() throws IOException %7B%0A        Mongo mongo = new MongoClient(new MongoClientURI(productionMongoUrl));%0A        MongoOperations mongoTemplate = new MongoTemplate(mongo, database);%0A        return mongoTemplate;%0A    %7D%0A%7D%0A%0A

add mongodb embedded (auto start on local machine with auto-cleanup) for development profile