From aa277670c07ddb097db8a2d6ad10293454022d36 Mon Sep 17 00:00:00 2001 From: zhaiyongchao Date: Sun, 18 Mar 2018 23:27:12 +0800 Subject: [PATCH] =?UTF-8?q?Spring=20Boot=E4=B8=AD=E5=A2=9E=E5=BC=BA?= =?UTF-8?q?=E5=AF=B9MongoDB=E7=9A=84=E9=85=8D=E7=BD=AE=EF=BC=88=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E6=B1=A0=E7=AD=89=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Chapter3-2-11/pom.xml | 68 +++++++++++++++++++ .../main/java/com/didispace/Application.java | 15 ++++ .../src/main/resources/application.properties | 4 ++ .../java/com/didispace/ApplicationTests.java | 27 ++++++++ README.md | 2 +- 5 files changed, 115 insertions(+), 1 deletion(-) create mode 100755 Chapter3-2-11/pom.xml create mode 100755 Chapter3-2-11/src/main/java/com/didispace/Application.java create mode 100644 Chapter3-2-11/src/main/resources/application.properties create mode 100755 Chapter3-2-11/src/test/java/com/didispace/ApplicationTests.java diff --git a/Chapter3-2-11/pom.xml b/Chapter3-2-11/pom.xml new file mode 100755 index 0000000..d9ac4cf --- /dev/null +++ b/Chapter3-2-11/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + com.didispace + Chapter3-2-11 + 1.0.0 + jar + + Chapter3-2-11 + Spring Boot project + + + org.springframework.boot + spring-boot-starter-parent + 1.5.10.RELEASE + + + + + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.springframework.boot + spring-boot-starter-data-mongodb + + + + com.spring4all + mongodb-plus-spring-boot-starter + 1.0.0.RELEASE + + + + org.projectlombok + lombok + 1.16.12 + provided + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/Chapter3-2-11/src/main/java/com/didispace/Application.java b/Chapter3-2-11/src/main/java/com/didispace/Application.java new file mode 100755 index 0000000..8904204 --- /dev/null +++ b/Chapter3-2-11/src/main/java/com/didispace/Application.java @@ -0,0 +1,15 @@ +package com.didispace; + +import com.spring4all.mongodb.EnableMongoPlus; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@EnableMongoPlus +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/Chapter3-2-11/src/main/resources/application.properties b/Chapter3-2-11/src/main/resources/application.properties new file mode 100644 index 0000000..e3f19a1 --- /dev/null +++ b/Chapter3-2-11/src/main/resources/application.properties @@ -0,0 +1,4 @@ +spring.data.mongodb.uri=mongodb://localhost:27017/test + +spring.data.mongodb.option.min-connection-per-host=20 +spring.data.mongodb.option.max-connection-per-host=200 diff --git a/Chapter3-2-11/src/test/java/com/didispace/ApplicationTests.java b/Chapter3-2-11/src/test/java/com/didispace/ApplicationTests.java new file mode 100755 index 0000000..b367136 --- /dev/null +++ b/Chapter3-2-11/src/test/java/com/didispace/ApplicationTests.java @@ -0,0 +1,27 @@ +package com.didispace; + +import com.mongodb.MongoClient; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + + +@RunWith(SpringRunner.class) +@SpringBootTest +@Slf4j +public class ApplicationTests { + + @Autowired + private MongoClient mongoClient; + + @Test + public void test() throws Exception { + log.info("MinConnectionsPerHost = {}, MaxConnectionsPerHost = {}", + mongoClient.getMongoClientOptions().getMinConnectionsPerHost(), + mongoClient.getMongoClientOptions().getConnectionsPerHost()); + } + +} diff --git a/README.md b/README.md index 653f86b..8a162ba 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,6 @@ #### 工程配置 - chapter2-1-1:[配置文件详解:自定义属性、随机数、多环境配置等](http://blog.didispace.com/springbootproperties/) -- chapter2-2-1:[配置文件详解:自定义属性、随机数、多环境配置等](http://blog.didispace.com/springbootproperties/) #### Web开发 @@ -63,6 +62,7 @@ - chapter3-2-8:[MyBatis注解配置详解](http://blog.didispace.com/mybatisinfo/) - chapter3-2-9:[使用Flyway来管理数据库版本](http://blog.didispace.com/spring-boot-flyway-db-version/) - chapter3-2-10:[使用LDAP来统一管理用户信息](http://blog.didispace.com/spring-boot-ldap-user/) +- chapter3-2-11:[Spring Boot中增强对MongoDB的配置(连接池等)](http://blog.didispace.com/springbootmongodb-plus/) #### 事务管理