Skip to content

Commit 517a399

Browse files
committed
Bump to Spring Boot 2.6.2 #63
1 parent 86408df commit 517a399

File tree

12 files changed

+81
-27
lines changed

12 files changed

+81
-27
lines changed

pom.xml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,34 @@
55

66
<groupId>org.springframework.samples</groupId>
77
<artifactId>spring-petclinic-rest</artifactId>
8-
<version>2.4.2</version>
8+
<version>2.6.2</version>
99

1010
<description>REST version of the Spring Petclinic sample application</description>
1111
<url>https://spring-petclinic.github.io/</url>
1212

1313
<parent>
1414
<groupId>org.springframework.boot</groupId>
1515
<artifactId>spring-boot-starter-parent</artifactId>
16-
<version>2.4.2</version>
16+
<version>2.6.2</version>
1717
<relativePath/> <!-- lookup parent from Maven repository -->
1818
</parent>
1919

2020
<properties>
21+
<!-- Third librairies -->
2122
<spring-data-jdbc.version>1.2.1.RELEASE</spring-data-jdbc.version>
2223
<springfox-swagger.version>3.0.0</springfox-swagger.version>
23-
<jacoco.version>0.8.7</jacoco.version>
24-
<docker.jib-maven-plugin.version>1.3.0</docker.jib-maven-plugin.version>
25-
<docker.image.prefix>springcommunity</docker.image.prefix>
26-
<jsr305.version>3.0.2</jsr305.version>
2724
<jackson-databind-nullable.version>0.2.1</jackson-databind-nullable.version>
2825
<mapstruct.version>1.4.1.Final</mapstruct.version>
2926
<jaxb-api.version>2.3.0</jaxb-api.version>
27+
28+
<!-- Maven plugins -->
29+
<jacoco.version>0.8.7</jacoco.version>
3030
<openapi-generator-maven-plugin.version>5.2.1</openapi-generator-maven-plugin.version>
3131
<build-helper-maven-plugin.version>3.2.0</build-helper-maven-plugin.version>
32+
33+
<!-- Docker -->
34+
<docker.jib-maven-plugin.version>1.3.0</docker.jib-maven-plugin.version>
35+
<docker.image.prefix>springcommunity</docker.image.prefix>
3236
</properties>
3337

3438
<dependencies>

src/main/java/org/springframework/samples/petclinic/util/ApplicationSwaggerConfig.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,28 @@
1717
package org.springframework.samples.petclinic.util;
1818

1919

20+
import org.springframework.beans.BeansException;
21+
import org.springframework.beans.factory.config.BeanPostProcessor;
2022
import org.springframework.context.annotation.Bean;
2123
import org.springframework.context.annotation.ComponentScan;
2224
import org.springframework.context.annotation.Configuration;
2325

26+
import org.springframework.util.ReflectionUtils;
27+
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;
2428
import springfox.documentation.builders.PathSelectors;
2529
import springfox.documentation.builders.RequestHandlerSelectors;
2630
import springfox.documentation.service.ApiInfo;
2731
import springfox.documentation.service.Contact;
2832
import springfox.documentation.spi.DocumentationType;
2933
import springfox.documentation.spring.web.plugins.Docket;
34+
import springfox.documentation.spring.web.plugins.WebFluxRequestHandlerProvider;
35+
import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider;
3036
import springfox.documentation.swagger2.annotations.EnableSwagger2;
3137

38+
import java.lang.reflect.Field;
3239
import java.util.Collections;
40+
import java.util.List;
41+
import java.util.stream.Collectors;
3342

3443
/**
3544
* Java config for Springfox swagger documentation plugin
@@ -67,5 +76,38 @@ private ApiInfo getApiInfo() {
6776
"http://www.apache.org/licenses/LICENSE-2.0", Collections.emptyList());
6877
}
6978

79+
/**
80+
* Springfox workaround required by Spring Boot 2.6
81+
* See https://github.com/springfox/springfox/issues/346
82+
*/
83+
@Bean
84+
public static BeanPostProcessor springfoxHandlerProviderBeanPostProcessor() {
85+
return new BeanPostProcessor() {
86+
87+
@Override
88+
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
89+
if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) {
90+
customizeSpringfoxHandlerMappings(getHandlerMappings(bean));
91+
}
92+
return bean;
93+
}
94+
95+
private <T extends RequestMappingInfoHandlerMapping> void customizeSpringfoxHandlerMappings(List<T> mappings) {
96+
mappings.removeIf(mapping -> mapping.getPatternParser() != null);
97+
}
98+
99+
@SuppressWarnings("unchecked")
100+
private List<RequestMappingInfoHandlerMapping> getHandlerMappings(Object bean) {
101+
try {
102+
Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings");
103+
field.setAccessible(true);
104+
return (List<RequestMappingInfoHandlerMapping>) field.get(bean);
105+
} catch (IllegalArgumentException | IllegalAccessException e) {
106+
throw new IllegalStateException(e);
107+
}
108+
}
109+
};
110+
}
111+
70112

71113
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# HSQLDB config start
22
#----------------------------------------------------------------
33

4-
spring.datasource.schema=classpath*:db/hsqldb/initDB.sql
5-
spring.datasource.data=classpath*:db/hsqldb/populateDB.sql
4+
spring.sql.init.schema-locations=classpath*:db/hsqldb/initDB.sql
5+
spring.sql.init.data-locations=classpath*:db/hsqldb/populateDB.sql
66

77
spring.datasource.url=jdbc:hsqldb:mem:petclinic
88
spring.datasource.username=sa
@@ -11,4 +11,4 @@ spring.jpa.database=HSQL
1111
spring.jpa.database-platform=org.hibernate.dialect.HSQLDialect
1212
spring.jpa.hibernate.ddl-auto=none
1313
#----------------------------------------------------------------
14-
# HSQLDB config end
14+
# HSQLDB config end

src/main/resources/application-mysql.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# uncomment for init database (first start)
2-
#spring.datasource.initialization-mode=always
3-
#spring.datasource.schema=classpath*:db/mysql/initDB.sql
4-
#spring.datasource.data=classpath*:db/mysql/populateDB.sql
2+
#spring.sql.init.mode=always
3+
#spring.sql.init.schema-locations=classpath*:db/mysql/initDB.sql
4+
#spring.sql.init.data-locations=classpath*:db/mysql/populateDB.sql
55

66
# MySQL config start
77
#----------------------------------------------------------------

src/main/resources/application-postgresql.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# uncomment for init database (first start)
2-
#spring.datasource.initialization-mode=always
3-
#spring.datasource.schema=classpath*:db/postgresql/initDB.sql
4-
#spring.datasource.data=classpath*:db/postgresql/populateDB.sql
2+
#spring.sql.init.mode=always
3+
#spring.sql.init.schema-locations=classpath*:db/postgresql/initDB.sql
4+
#spring.sql.init.data-locations=classpath*:db/postgresql/populateDB.sql
55

66
# PostgreSQL config start
77
#----------------------------------------------------------------

src/main/resources/application.properties

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ spring.profiles.active=hsqldb,spring-data-jpa
2323
server.port=9966
2424
server.servlet.context-path=/petclinic/
2525

26+
# Springfox workaround required by Spring Boot 2.6
27+
# See https://github.com/springfox/springfox/issues/3462
28+
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
29+
2630
spring.messages.basename=messages/messages
31+
spring.jpa.open-in-view=false
2732

2833
logging.level.org.springframework=INFO
2934
#logging.level.org.springframework=DEBUG
@@ -35,7 +40,3 @@ logging.level.org.springframework=INFO
3540
# by default the authentication is disabled
3641
petclinic.security.enable=false
3742

38-
# ------------------------------------------------
39-
# Spring doc configuration
40-
springdoc.api-docs.enabled=true
41-
springdoc.writer-with-default-pretty-printer= true

src/test/java/org/springframework/samples/petclinic/rest/OwnerRestControllerTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void initOwners() {
7676
this.mockMvc = MockMvcBuilders.standaloneSetup(ownerRestController)
7777
.setControllerAdvice(new ExceptionControllerAdvice())
7878
.build();
79-
owners = new ArrayList<OwnerDto>();
79+
owners = new ArrayList<>();
8080

8181
OwnerDto ownerWithPet = new OwnerDto();
8282
owners.add(ownerWithPet.id(1).firstName("George").lastName("Franklin").address("110 W. Liberty St.").city("Madison").telephone("6085551023").addPetsItem(getTestPetWithIdAndName(ownerWithPet, 1, "Rosy")));
@@ -304,6 +304,7 @@ void testUpdateOwnerError() throws Exception {
304304
OwnerDto newOwnerDto = owners.get(0);
305305
newOwnerDto.setFirstName("");
306306
ObjectMapper mapper = new ObjectMapper();
307+
mapper.registerModule(new JavaTimeModule());
307308
String newOwnerAsJSON = mapper.writeValueAsString(newOwnerDto);
308309
this.mockMvc.perform(put("/api/owners/1")
309310
.content(newOwnerAsJSON).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE))
@@ -315,6 +316,7 @@ void testUpdateOwnerError() throws Exception {
315316
void testDeleteOwnerSuccess() throws Exception {
316317
OwnerDto newOwnerDto = owners.get(0);
317318
ObjectMapper mapper = new ObjectMapper();
319+
mapper.registerModule(new JavaTimeModule());
318320
String newOwnerAsJSON = mapper.writeValueAsString(newOwnerDto);
319321
final Owner owner = ownerMapper.toOwner(owners.get(0));
320322
given(this.clinicService.findOwnerById(1)).willReturn(owner);
@@ -328,6 +330,7 @@ void testDeleteOwnerSuccess() throws Exception {
328330
void testDeleteOwnerError() throws Exception {
329331
OwnerDto newOwnerDto = owners.get(0);
330332
ObjectMapper mapper = new ObjectMapper();
333+
mapper.registerModule(new JavaTimeModule());
331334
String newOwnerAsJSON = mapper.writeValueAsString(newOwnerDto);
332335
given(this.clinicService.findOwnerById(-1)).willReturn(null);
333336
this.mockMvc.perform(delete("/api/owners/-1")

src/test/java/org/springframework/samples/petclinic/rest/PetRestControllerTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ void testCreatePetError() throws Exception {
176176
ObjectMapper mapper = new ObjectMapper();
177177
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
178178
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
179+
mapper.registerModule(new JavaTimeModule());
179180
String newPetAsJSON = mapper.writeValueAsString(newPet);
180181
this.mockMvc.perform(post("/api/pets/")
181182
.content(newPetAsJSON).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE))
@@ -214,6 +215,7 @@ void testUpdatePetError() throws Exception {
214215
PetDto newPet = pets.get(0);
215216
newPet.setName(null);
216217
ObjectMapper mapper = new ObjectMapper();
218+
mapper.registerModule(new JavaTimeModule());
217219
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
218220
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
219221
String newPetAsJSON = mapper.writeValueAsString(newPet);
@@ -228,6 +230,7 @@ void testUpdatePetError() throws Exception {
228230
void testDeletePetSuccess() throws Exception {
229231
PetDto newPet = pets.get(0);
230232
ObjectMapper mapper = new ObjectMapper();
233+
mapper.registerModule(new JavaTimeModule());
231234
String newPetAsJSON = mapper.writeValueAsString(newPet);
232235
given(this.clinicService.findPetById(3)).willReturn(petMapper.toPet(pets.get(0)));
233236
this.mockMvc.perform(delete("/api/pets/3")
@@ -240,6 +243,7 @@ void testDeletePetSuccess() throws Exception {
240243
void testDeletePetError() throws Exception {
241244
PetDto newPet = pets.get(0);
242245
ObjectMapper mapper = new ObjectMapper();
246+
mapper.registerModule(new JavaTimeModule());
243247
String newPetAsJSON = mapper.writeValueAsString(newPet);
244248
given(this.clinicService.findPetById(-1)).willReturn(null);
245249
this.mockMvc.perform(delete("/api/pets/-1")

src/test/java/org/springframework/samples/petclinic/rest/VisitRestControllerTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ void testUpdateVisitError() throws Exception {
225225
void testDeleteVisitSuccess() throws Exception {
226226
Visit newVisit = visits.get(0);
227227
ObjectMapper mapper = new ObjectMapper();
228+
mapper.registerModule(new JavaTimeModule());
228229
String newVisitAsJSON = mapper.writeValueAsString(visitMapper.toVisitDto(newVisit));
229230
given(this.clinicService.findVisitById(2)).willReturn(visits.get(0));
230231
this.mockMvc.perform(delete("/api/visits/2")
@@ -237,6 +238,7 @@ void testDeleteVisitSuccess() throws Exception {
237238
void testDeleteVisitError() throws Exception {
238239
Visit newVisit = visits.get(0);
239240
ObjectMapper mapper = new ObjectMapper();
241+
mapper.registerModule(new JavaTimeModule());
240242
String newVisitAsJSON = mapper.writeValueAsString(visitMapper.toVisitDto(newVisit));
241243
given(this.clinicService.findVisitById(-1)).willReturn(null);
242244
this.mockMvc.perform(delete("/api/visits/-1")

src/test/java/org/springframework/samples/petclinic/service/clinicService/ApplicationTestConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
public class ApplicationTestConfig {
88

99
public ApplicationTestConfig(){
10-
MockitoAnnotations.initMocks(this);
10+
MockitoAnnotations.openMocks(this);
1111
}
1212

1313
}

0 commit comments

Comments
 (0)