Skip to content

Commit

Permalink
Bump to Spring Boot 2.6.2 #63
Browse files Browse the repository at this point in the history
  • Loading branch information
arey committed Dec 28, 2021
1 parent 86408df commit 517a399
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 27 deletions.
16 changes: 10 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,34 @@

<groupId>org.springframework.samples</groupId>
<artifactId>spring-petclinic-rest</artifactId>
<version>2.4.2</version>
<version>2.6.2</version>

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

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
<version>2.6.2</version>
<relativePath/> <!-- lookup parent from Maven repository -->
</parent>

<properties>
<!-- Third librairies -->
<spring-data-jdbc.version>1.2.1.RELEASE</spring-data-jdbc.version>
<springfox-swagger.version>3.0.0</springfox-swagger.version>
<jacoco.version>0.8.7</jacoco.version>
<docker.jib-maven-plugin.version>1.3.0</docker.jib-maven-plugin.version>
<docker.image.prefix>springcommunity</docker.image.prefix>
<jsr305.version>3.0.2</jsr305.version>
<jackson-databind-nullable.version>0.2.1</jackson-databind-nullable.version>
<mapstruct.version>1.4.1.Final</mapstruct.version>
<jaxb-api.version>2.3.0</jaxb-api.version>

<!-- Maven plugins -->
<jacoco.version>0.8.7</jacoco.version>
<openapi-generator-maven-plugin.version>5.2.1</openapi-generator-maven-plugin.version>
<build-helper-maven-plugin.version>3.2.0</build-helper-maven-plugin.version>

<!-- Docker -->
<docker.jib-maven-plugin.version>1.3.0</docker.jib-maven-plugin.version>
<docker.image.prefix>springcommunity</docker.image.prefix>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,28 @@
package org.springframework.samples.petclinic.util;


import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import org.springframework.util.ReflectionUtils;
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.spring.web.plugins.WebFluxRequestHandlerProvider;
import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.lang.reflect.Field;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

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

/**
* Springfox workaround required by Spring Boot 2.6
* See https://github.com/springfox/springfox/issues/346
*/
@Bean
public static BeanPostProcessor springfoxHandlerProviderBeanPostProcessor() {
return new BeanPostProcessor() {

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) {
customizeSpringfoxHandlerMappings(getHandlerMappings(bean));
}
return bean;
}

private <T extends RequestMappingInfoHandlerMapping> void customizeSpringfoxHandlerMappings(List<T> mappings) {
mappings.removeIf(mapping -> mapping.getPatternParser() != null);
}

@SuppressWarnings("unchecked")
private List<RequestMappingInfoHandlerMapping> getHandlerMappings(Object bean) {
try {
Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings");
field.setAccessible(true);
return (List<RequestMappingInfoHandlerMapping>) field.get(bean);
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
}
};
}


}
6 changes: 3 additions & 3 deletions src/main/resources/application-hsqldb.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# HSQLDB config start
#----------------------------------------------------------------

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

spring.datasource.url=jdbc:hsqldb:mem:petclinic
spring.datasource.username=sa
Expand All @@ -11,4 +11,4 @@ spring.jpa.database=HSQL
spring.jpa.database-platform=org.hibernate.dialect.HSQLDialect
spring.jpa.hibernate.ddl-auto=none
#----------------------------------------------------------------
# HSQLDB config end
# HSQLDB config end
6 changes: 3 additions & 3 deletions src/main/resources/application-mysql.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# uncomment for init database (first start)
#spring.datasource.initialization-mode=always
#spring.datasource.schema=classpath*:db/mysql/initDB.sql
#spring.datasource.data=classpath*:db/mysql/populateDB.sql
#spring.sql.init.mode=always
#spring.sql.init.schema-locations=classpath*:db/mysql/initDB.sql
#spring.sql.init.data-locations=classpath*:db/mysql/populateDB.sql

# MySQL config start
#----------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/application-postgresql.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# uncomment for init database (first start)
#spring.datasource.initialization-mode=always
#spring.datasource.schema=classpath*:db/postgresql/initDB.sql
#spring.datasource.data=classpath*:db/postgresql/populateDB.sql
#spring.sql.init.mode=always
#spring.sql.init.schema-locations=classpath*:db/postgresql/initDB.sql
#spring.sql.init.data-locations=classpath*:db/postgresql/populateDB.sql

# PostgreSQL config start
#----------------------------------------------------------------
Expand Down
9 changes: 5 additions & 4 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ spring.profiles.active=hsqldb,spring-data-jpa
server.port=9966
server.servlet.context-path=/petclinic/

# Springfox workaround required by Spring Boot 2.6
# See https://github.com/springfox/springfox/issues/3462
spring.mvc.pathmatch.matching-strategy=ant_path_matcher

spring.messages.basename=messages/messages
spring.jpa.open-in-view=false

logging.level.org.springframework=INFO
#logging.level.org.springframework=DEBUG
Expand All @@ -35,7 +40,3 @@ logging.level.org.springframework=INFO
# by default the authentication is disabled
petclinic.security.enable=false

# ------------------------------------------------
# Spring doc configuration
springdoc.api-docs.enabled=true

This comment has been minimized.

Copy link
@andrei-ivanov

andrei-ivanov Jan 7, 2022

maybe SpringFox should have been removed instead and SpringDoc used, since it appears to have Boot 2.6 compatibility

springdoc.writer-with-default-pretty-printer= true
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void initOwners() {
this.mockMvc = MockMvcBuilders.standaloneSetup(ownerRestController)
.setControllerAdvice(new ExceptionControllerAdvice())
.build();
owners = new ArrayList<OwnerDto>();
owners = new ArrayList<>();

OwnerDto ownerWithPet = new OwnerDto();
owners.add(ownerWithPet.id(1).firstName("George").lastName("Franklin").address("110 W. Liberty St.").city("Madison").telephone("6085551023").addPetsItem(getTestPetWithIdAndName(ownerWithPet, 1, "Rosy")));
Expand Down Expand Up @@ -304,6 +304,7 @@ void testUpdateOwnerError() throws Exception {
OwnerDto newOwnerDto = owners.get(0);
newOwnerDto.setFirstName("");
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
String newOwnerAsJSON = mapper.writeValueAsString(newOwnerDto);
this.mockMvc.perform(put("/api/owners/1")
.content(newOwnerAsJSON).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE))
Expand All @@ -315,6 +316,7 @@ void testUpdateOwnerError() throws Exception {
void testDeleteOwnerSuccess() throws Exception {
OwnerDto newOwnerDto = owners.get(0);
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
String newOwnerAsJSON = mapper.writeValueAsString(newOwnerDto);
final Owner owner = ownerMapper.toOwner(owners.get(0));
given(this.clinicService.findOwnerById(1)).willReturn(owner);
Expand All @@ -328,6 +330,7 @@ void testDeleteOwnerSuccess() throws Exception {
void testDeleteOwnerError() throws Exception {
OwnerDto newOwnerDto = owners.get(0);
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
String newOwnerAsJSON = mapper.writeValueAsString(newOwnerDto);
given(this.clinicService.findOwnerById(-1)).willReturn(null);
this.mockMvc.perform(delete("/api/owners/-1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ void testCreatePetError() throws Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.registerModule(new JavaTimeModule());
String newPetAsJSON = mapper.writeValueAsString(newPet);
this.mockMvc.perform(post("/api/pets/")
.content(newPetAsJSON).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE))
Expand Down Expand Up @@ -214,6 +215,7 @@ void testUpdatePetError() throws Exception {
PetDto newPet = pets.get(0);
newPet.setName(null);
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
String newPetAsJSON = mapper.writeValueAsString(newPet);
Expand All @@ -228,6 +230,7 @@ void testUpdatePetError() throws Exception {
void testDeletePetSuccess() throws Exception {
PetDto newPet = pets.get(0);
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
String newPetAsJSON = mapper.writeValueAsString(newPet);
given(this.clinicService.findPetById(3)).willReturn(petMapper.toPet(pets.get(0)));
this.mockMvc.perform(delete("/api/pets/3")
Expand All @@ -240,6 +243,7 @@ void testDeletePetSuccess() throws Exception {
void testDeletePetError() throws Exception {
PetDto newPet = pets.get(0);
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
String newPetAsJSON = mapper.writeValueAsString(newPet);
given(this.clinicService.findPetById(-1)).willReturn(null);
this.mockMvc.perform(delete("/api/pets/-1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ void testUpdateVisitError() throws Exception {
void testDeleteVisitSuccess() throws Exception {
Visit newVisit = visits.get(0);
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
String newVisitAsJSON = mapper.writeValueAsString(visitMapper.toVisitDto(newVisit));
given(this.clinicService.findVisitById(2)).willReturn(visits.get(0));
this.mockMvc.perform(delete("/api/visits/2")
Expand All @@ -237,6 +238,7 @@ void testDeleteVisitSuccess() throws Exception {
void testDeleteVisitError() throws Exception {
Visit newVisit = visits.get(0);
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
String newVisitAsJSON = mapper.writeValueAsString(visitMapper.toVisitDto(newVisit));
given(this.clinicService.findVisitById(-1)).willReturn(null);
this.mockMvc.perform(delete("/api/visits/-1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class ApplicationTestConfig {

public ApplicationTestConfig(){
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class AbstractUserServiceTests {

@BeforeEach
public void init() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
}

@Test
Expand Down
8 changes: 3 additions & 5 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ spring.profiles.active=hsqldb,spring-data-jpa
# ------------------------------------------------

server.port=9966
server.context-path=/petclinic/
server.servlet.context-path=/petclinic/
spring.jpa.open-in-view=false

spring.messages.basename=messages/messages
logging.level.org.springframework=INFO
Expand All @@ -35,7 +36,4 @@ logging.level.org.springframework=INFO
security.ignored=/**
basic.authentication.enabled=true
petclinic.security.enable=true
# ------------------------------------------------
# Spring doc configuration
springdoc.api-docs.enabled=true
springdoc.writer-with-default-pretty-printer=true

0 comments on commit 517a399

Please sign in to comment.