Skip to content

Commit b3b8ee2

Browse files
committed
update all the dependencies for MongoDB 4.4 and Swagger 3
1 parent 0e02444 commit b3b8ee2

File tree

6 files changed

+41
-60
lines changed

6 files changed

+41
-60
lines changed

README.md

+14-11
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
## Supported versions:
44

5-
- Java 8 to 13
6-
- Spring boot 2.2.0.RELEASE
7-
- MongoDB 4.2.1
8-
- MongoDB Java driver 3.11.1
9-
- Maven 3.6.2
5+
- Java 8 to 15
6+
- Spring boot 2.4.2
7+
- MongoDB 4.4.3
8+
- MongoDB Java driver 4.1.1
9+
- Maven 3.6.3
10+
- Swagger 3.0.0
1011

1112
## MongoDB Atlas
1213

13-
- Get started with a Free Tier Cluster on [MongoDB Atlas](http://bit.ly/mongodb-meetatlas).
14-
- Read this blog post: [Quick Start - Getting your Free MongoDB Atlas Cluster](https://www.mongodb.com/blog/post/quick-start-getting-your-free-mongodb-atlas-cluster).
14+
- Get started with a Free Tier Cluster on [MongoDB Atlas](https://www.mongodb.com/cloud/atlas).
15+
- Read this blog post: [Quick Start - Getting your Free MongoDB Atlas Cluster](https://developer.mongodb.com/quickstart/free-atlas-cluster).
1516
- You will need to update the default MongoDB URI `spring.data.mongodb.uri` in the `application.properties` file.
1617

1718
## Commands
@@ -22,9 +23,11 @@
2223
- You can build the project with : `mvn clean package`.
2324
- You can run the project with the fat jar and the embedded Tomcat: `java -jar target/java-spring-boot-mongodb-starter-1.0.0.jar` but I would use a real tomcat in production.
2425

25-
## Swagger
26-
- Swagger is already configured in this project in `SwaggerConfig.java`.
27-
- The API can be seen at [http://localhost:8080/swagger-ui.html](http://localhost:8080/swagger-ui.html).
26+
## Swagger 3
27+
- Swagger 3 is already configured in this project in `SpringFoxConfig.java`.
28+
- The Swagger UI can be seen at [http://localhost:8080/swagger-ui/index.html](http://localhost:8080/swagger-ui/index.html).
29+
- The Swagger API documentation 2.0 is at [http://localhost:8080/v2/api-docs](http://localhost:8080/v2/api-docs).
30+
- The Open API documentation 3.0.3 is at [http://localhost:8080/v3/api-docs](http://localhost:8080/v3/api-docs).
2831
- You can also try the entire REST API directly from the Swagger interface!
2932

3033
## Features showcase
@@ -38,7 +41,7 @@ This project showcases several features of MongoDB:
3841

3942
And some other cool stuff:
4043
- You can change the default Spring Boot logo by adding a banner.txt file in your properties.
41-
- You don't have to use Spring Data MongoDB. The MongoDB driver is more flexible and already provide everything you need to code efficiently and optimise your queries correctly.
44+
- You don't have to use Spring Data MongoDB. The MongoDB driver is more flexible and already provides everything you need to code efficiently and optimise your queries correctly.
4245

4346
## Author
4447
- Maxime Beugnet @ MongoDB.

pom.xml

+7-15
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313
<parent>
1414
<groupId>org.springframework.boot</groupId>
1515
<artifactId>spring-boot-starter-parent</artifactId>
16-
<version>2.2.0.RELEASE</version>
16+
<version>2.4.2</version>
1717
<relativePath/>
1818
</parent>
1919

2020
<properties>
2121
<java.version>8</java.version>
2222
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2323
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24-
<mongodb.version>3.11.1</mongodb.version>
25-
<springfox-swagger2.version>2.9.2</springfox-swagger2.version>
26-
<junit-engine.version>5.5.2</junit-engine.version>
27-
<assertj-core.version>3.13.2</assertj-core.version>
24+
<mongodb.version>4.1.1</mongodb.version>
25+
<junit-engine.version>5.7.0</junit-engine.version>
26+
<assertj-core.version>3.18.1</assertj-core.version>
2827
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
28+
<springfox-boot-starter.version>3.0.0</springfox-boot-starter.version>
2929
</properties>
3030

3131
<dependencies>
@@ -40,15 +40,8 @@
4040
</dependency>
4141
<dependency>
4242
<groupId>io.springfox</groupId>
43-
<artifactId>springfox-swagger2</artifactId>
44-
<version>${springfox-swagger2.version}</version>
45-
<scope>compile</scope>
46-
</dependency>
47-
<dependency>
48-
<groupId>io.springfox</groupId>
49-
<artifactId>springfox-swagger-ui</artifactId>
50-
<version>${springfox-swagger2.version}</version>
51-
<scope>compile</scope>
43+
<artifactId>springfox-boot-starter</artifactId>
44+
<version>${springfox-boot-starter.version}</version>
5245
</dependency>
5346
<dependency>
5447
<groupId>org.springframework.boot</groupId>
@@ -90,7 +83,6 @@
9083
<plugin>
9184
<groupId>org.springframework.boot</groupId>
9285
<artifactId>spring-boot-maven-plugin</artifactId>
93-
<version>${project.parent.version}</version>
9486
</plugin>
9587
<plugin>
9688
<groupId>org.apache.maven.plugins</groupId>

src/main/java/com/mongodb/starter/SwaggerConfig.java renamed to src/main/java/com/mongodb/starter/SpringFoxConfig.java

+2-20
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,16 @@
22

33
import org.springframework.context.annotation.Bean;
44
import org.springframework.context.annotation.Configuration;
5-
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
6-
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
7-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
85
import springfox.documentation.builders.ApiInfoBuilder;
96
import springfox.documentation.builders.PathSelectors;
107
import springfox.documentation.builders.RequestHandlerSelectors;
118
import springfox.documentation.service.ApiInfo;
129
import springfox.documentation.service.Contact;
1310
import springfox.documentation.spi.DocumentationType;
1411
import springfox.documentation.spring.web.plugins.Docket;
15-
import springfox.documentation.swagger2.annotations.EnableSwagger2;
16-
17-
import static com.google.common.base.Predicates.not;
1812

1913
@Configuration
20-
@EnableSwagger2
21-
public class SwaggerConfig extends WebMvcConfigurationSupport {
14+
public class SpringFoxConfig {
2215
@Bean
2316
public Docket api() {
2417
return new Docket(DocumentationType.SWAGGER_2).select()
@@ -35,18 +28,7 @@ private ApiInfo info() {
3528
"maxime.beugnet@gmail.com"))
3629
.version("1.0.0")
3730
.license("Apache License Version 2.0")
38-
.licenseUrl("https://www.apache.org/licenses/LICENSE-2.0\"")
31+
.licenseUrl("https://www.apache.org/licenses/LICENSE-2.0")
3932
.build();
4033
}
41-
42-
@Override
43-
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
44-
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
45-
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
46-
}
47-
48-
@Override
49-
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
50-
configurer.enable();
51-
}
5234
}

src/main/java/com/mongodb/starter/repositories/MongoDBPersonRepository.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.bson.BsonNull;
1717
import org.bson.conversions.Bson;
1818
import org.bson.types.ObjectId;
19-
import org.springframework.beans.factory.annotation.Autowired;
2019
import org.springframework.stereotype.Repository;
2120

2221
import javax.annotation.PostConstruct;
@@ -41,10 +40,13 @@ public class MongoDBPersonRepository implements PersonRepository {
4140
.readConcern(ReadConcern.MAJORITY)
4241
.writeConcern(WriteConcern.MAJORITY)
4342
.build();
44-
@Autowired
45-
private MongoClient client;
43+
private final MongoClient client;
4644
private MongoCollection<Person> personCollection;
4745

46+
public MongoDBPersonRepository(MongoClient mongoClient) {
47+
this.client = mongoClient;
48+
}
49+
4850
@PostConstruct
4951
void init() {
5052
personCollection = client.getDatabase("test").getCollection("persons", Person.class);

src/test/java/com/mongodb/starter/PersonControllerIT.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void postPerson() {
6363
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.CREATED);
6464
Person personResult = result.getBody();
6565
assertThat(personResult.getId()).isNotNull();
66-
assertThat(personResult).isEqualToIgnoringGivenFields(testHelper.getMax(), "id", "createdAt");
66+
assertThat(personResult).usingRecursiveComparison().ignoringFields("id", "createdAt").isEqualTo(testHelper.getMax());
6767
}
6868

6969
@DisplayName("POST /persons with 2 person")
@@ -116,8 +116,9 @@ void getPersonsByIds() {
116116
List<String> idsInserted = personsInserted.stream().map(Person::getId).map(ObjectId::toString).collect(toList());
117117
// WHEN
118118
String url = URL + "/persons/" + String.join(",", idsInserted);
119-
ResponseEntity<List<Person>> result = rest.exchange(url, HttpMethod.GET, null, new ParameterizedTypeReference<List<Person>>() {
120-
});
119+
ResponseEntity<List<Person>> result = rest.exchange(url, HttpMethod.GET, null,
120+
new ParameterizedTypeReference<List<Person>>() {
121+
});
121122
// THEN
122123
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
123124
assertThat(result.getBody()).containsExactlyInAnyOrderElementsOf(personsInserted);
@@ -191,8 +192,9 @@ void putPerson() {
191192
personInserted.setAge(32);
192193
personInserted.setInsurance(false);
193194
HttpEntity<Person> body = new HttpEntity<>(personInserted);
194-
ResponseEntity<Person> result = rest.exchange(URL + "/person", HttpMethod.PUT, body, new ParameterizedTypeReference<Person>() {
195-
});
195+
ResponseEntity<Person> result = rest.exchange(URL + "/person", HttpMethod.PUT, body,
196+
new ParameterizedTypeReference<Person>() {
197+
});
196198
// THEN
197199
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
198200
assertThat(result.getBody()).isEqualTo(personRepository.findOne(personInserted.getId().toString()));
@@ -212,8 +214,9 @@ void putPersons() {
212214
personsInserted.get(1).setAge(28);
213215
personsInserted.get(1).setInsurance(true);
214216
HttpEntity<List<Person>> body = new HttpEntity<>(personsInserted);
215-
ResponseEntity<Long> result = rest.exchange(URL + "/persons", HttpMethod.PUT, body, new ParameterizedTypeReference<Long>() {
216-
});
217+
ResponseEntity<Long> result = rest.exchange(URL + "/persons", HttpMethod.PUT, body,
218+
new ParameterizedTypeReference<Long>() {
219+
});
217220
// THEN
218221
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
219222
assertThat(result.getBody()).isEqualTo(2L);

src/test/java/com/mongodb/starter/TestHelper.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.List;
99

1010
import static java.util.Arrays.asList;
11+
import static java.util.Collections.singletonList;
1112

1213
@Component
1314
class TestHelper {
@@ -22,9 +23,7 @@ Person getMax() {
2223
.setStreet("The Best Street"))
2324
.setAge(31)
2425
.setInsurance(true)
25-
.setCars(asList(new Car().setBrand("Ferrari")
26-
.setMaxSpeedKmH(339f)
27-
.setModel("SF90 Stradale")));
26+
.setCars(singletonList(new Car().setBrand("Ferrari").setMaxSpeedKmH(339f).setModel("SF90 Stradale")));
2827
}
2928

3029
Person getAlex() {
@@ -37,7 +36,7 @@ Person getAlex() {
3736
.setStreet("Another Street"))
3837
.setAge(27)
3938
.setInsurance(false)
40-
.setCars(asList(new Car().setBrand("Mercedes").setMaxSpeedKmH(355f).setModel("Project One")));
39+
.setCars(singletonList(new Car().setBrand("Mercedes").setMaxSpeedKmH(355f).setModel("Project One")));
4140
}
4241

4342
List<Person> getListMaxAlex() {

0 commit comments

Comments
 (0)