From a7402dd2ba63384db81c9297b8991fa517b3b332 Mon Sep 17 00:00:00 2001 From: Mariana Azevedo Date: Wed, 29 Jul 2020 23:19:43 -0300 Subject: [PATCH] Fixing logs; fixing Swagger dependency update to 2.10.5; fixing Spring Admin Client configuration. --- Procfile | 2 +- README.md | 7 ++++--- pom.xml | 4 ++-- .../v1/transaction/TransactionController.java | 10 ++++------ .../financialjavaapi/util/CacheEventLogger.java | 9 ++++----- .../util/config/FinancialApiConfiguration.java | 2 +- .../util/config/SwaggerConfiguration.java | 4 ++-- src/main/resources/application-prod.properties | 2 +- src/main/resources/application-test.properties | 2 +- src/main/resources/application.properties | 10 +++++++--- 10 files changed, 27 insertions(+), 25 deletions(-) diff --git a/Procfile b/Procfile index 2d684f6..4d437d5 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: java -jar -Dspring.profiles.active=prod -Dserver.port=$PORT target/financial-java-api-3.0.1-SNAPSHOT.jar \ No newline at end of file +web: java -jar -Dspring.profiles.active=prod -Dserver.port=$PORT target/financial-java-api-3.0.2-SNAPSHOT.jar \ No newline at end of file diff --git a/README.md b/README.md index 0139bb5..23f90f1 100644 --- a/README.md +++ b/README.md @@ -159,12 +159,13 @@ This project was developed with: * **Java 11 (Java Development Kit - JDK: 11.0.7)** * **Spring Boot 2.3.0** +* **Spring Admin Client 2.2.3** * **Maven** * **JUnit 5** * **Surfire** * **PostgreSQL 12** * **Flyway 6.4.1** -* **Swagger 2.9.2** +* **Swagger 2.10.5** * **Model Mapper 2.3.8** * **Heroku** * **EhCache** @@ -178,7 +179,7 @@ The API also was developed to run with an `jar`. In order to generate this `jar` mvn package ``` -It will clean, compile and generate a `jar` at target directory, e.g. `financial-java-api-3.0.1-SNAPSHOT.jar` +It will clean, compile and generate a `jar` at target directory, e.g. `financial-java-api-3.0.2-SNAPSHOT.jar` ### Execution @@ -216,7 +217,7 @@ mvn integration-test In order to run the API, run the jar simply as following: ```bash -java -jar financial-java-api-3.0.1-SNAPSHOT.jar --spring.profiles.active=prod +java -jar financial-java-api-3.0.2-SNAPSHOT.jar --spring.profiles.active=prod ``` or diff --git a/pom.xml b/pom.xml index 831706f..ee0a23c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ io.github.mariazevedo88 financial-java-api - 3.0.1-SNAPSHOT + 3.0.2-SNAPSHOT jar financial-java-api @@ -30,7 +30,7 @@ org.springframework.boot spring-boot-starter-parent - 2.3.1.RELEASE + 2.3.2.RELEASE diff --git a/src/main/java/io/github/mariazevedo88/financialjavaapi/controller/v1/transaction/TransactionController.java b/src/main/java/io/github/mariazevedo88/financialjavaapi/controller/v1/transaction/TransactionController.java index 0f50c83..e526468 100644 --- a/src/main/java/io/github/mariazevedo88/financialjavaapi/controller/v1/transaction/TransactionController.java +++ b/src/main/java/io/github/mariazevedo88/financialjavaapi/controller/v1/transaction/TransactionController.java @@ -10,8 +10,6 @@ import javax.validation.Valid; import org.modelmapper.ModelMapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.hateoas.Link; import org.springframework.hateoas.server.mvc.WebMvcLinkBuilder; @@ -39,6 +37,7 @@ import io.github.mariazevedo88.financialjavaapi.service.transaction.TransactionService; import io.github.mariazevedo88.financialjavaapi.util.FinancialApiUtil; import io.swagger.annotations.ApiOperation; +import lombok.extern.log4j.Log4j2; /** * SpringBoot RestController that creates all service endpoints related to the transaction. @@ -46,12 +45,11 @@ * @author Mariana Azevedo * @since 08/09/2019 */ +@Log4j2 @RestController @RequestMapping("/financial/v1/transactions") public class TransactionController { - private static final Logger logger = LoggerFactory.getLogger(TransactionController.class); - private TransactionService transactionService; @Autowired @@ -220,7 +218,7 @@ public ResponseEntity>> findAll(@RequestHeader(val try { createSelfLinkInCollections(apiVersion, apiKey, dto); } catch (TransactionNotFoundException e) { - logger.error("There are no transactions registered in the database."); + log.error("There are no transactions registered in the database."); } }); @@ -274,7 +272,7 @@ public ResponseEntity>> findByNsu(@RequestHeader(v try { createSelfLinkInCollections(apiVersion, apiKey, dto); } catch (TransactionNotFoundException e) { - logger.error("There are no transactions registered with the nsu=" + transactionNSU); + log.error("There are no transactions registered with the nsu=" + transactionNSU); } }); diff --git a/src/main/java/io/github/mariazevedo88/financialjavaapi/util/CacheEventLogger.java b/src/main/java/io/github/mariazevedo88/financialjavaapi/util/CacheEventLogger.java index 115d46b..1a84781 100644 --- a/src/main/java/io/github/mariazevedo88/financialjavaapi/util/CacheEventLogger.java +++ b/src/main/java/io/github/mariazevedo88/financialjavaapi/util/CacheEventLogger.java @@ -2,10 +2,10 @@ import org.ehcache.event.CacheEvent; import org.ehcache.event.CacheEventListener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; +import lombok.extern.log4j.Log4j2; + /** * Class that implements an event logger to show cache creation and expiration * in the API. @@ -13,17 +13,16 @@ * @author Mariana Azevedo * @since 11/06/2020 */ +@Log4j2 @Component public class CacheEventLogger implements CacheEventListener { - private static final Logger logger = LoggerFactory.getLogger(CacheEventLogger.class); - /** * @see CacheEventListener#onEvent(CacheEvent) */ @Override public void onEvent(CacheEvent cacheEvent) { - logger.info("Cache event {} for item with key {}. Old value = {}, New value = {}", cacheEvent.getType(), + log.info("Cache event {} for item with key {}. Old value = {}, New value = {}", cacheEvent.getType(), cacheEvent.getKey(), cacheEvent.getOldValue(), cacheEvent.getNewValue()); } diff --git a/src/main/java/io/github/mariazevedo88/financialjavaapi/util/config/FinancialApiConfiguration.java b/src/main/java/io/github/mariazevedo88/financialjavaapi/util/config/FinancialApiConfiguration.java index 43358db..36d5a2d 100644 --- a/src/main/java/io/github/mariazevedo88/financialjavaapi/util/config/FinancialApiConfiguration.java +++ b/src/main/java/io/github/mariazevedo88/financialjavaapi/util/config/FinancialApiConfiguration.java @@ -31,6 +31,6 @@ public class FinancialApiConfiguration { public LinkDiscoverers discoverers() { List plugins = new ArrayList<>(); plugins.add(new CollectionJsonLinkDiscoverer()); - return new LinkDiscoverers(SimplePluginRegistry.create(plugins)); + return new LinkDiscoverers(SimplePluginRegistry.of(plugins)); } } diff --git a/src/main/java/io/github/mariazevedo88/financialjavaapi/util/config/SwaggerConfiguration.java b/src/main/java/io/github/mariazevedo88/financialjavaapi/util/config/SwaggerConfiguration.java index 96e5ea6..aaf1c50 100644 --- a/src/main/java/io/github/mariazevedo88/financialjavaapi/util/config/SwaggerConfiguration.java +++ b/src/main/java/io/github/mariazevedo88/financialjavaapi/util/config/SwaggerConfiguration.java @@ -10,7 +10,7 @@ import springfox.documentation.service.ApiInfo; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.swagger2.annotations.EnableSwagger2; +import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; /** * Class that implements the necessary settings for using Swagger as an API documentation tool. @@ -20,7 +20,7 @@ */ @Configuration @Profile({"dev"}) -@EnableSwagger2 +@EnableSwagger2WebMvc public class SwaggerConfiguration { /** diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index c837ca1..77db2bc 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -18,7 +18,7 @@ pagination.items_per_page=10 jwt.secret=oioqowepjsjdasd!$%mknfskdnf090192019 jwt.expiration=6000 -api.version=2020-06-14 +api.version=2020-07-29 api.key="FX001-FREE" #Enable response compression diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index 401842c..cd17291 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -14,7 +14,7 @@ spring.cache.jcache.config=classpath:cache/ehcache.xml spring.mvc.throw-exception-if-no-handler-found=true spring.mvc.resources.add-mappings=false -api.version=2020-06-14 +api.version=2020-07-29 api.key="FX001-FREE" #Enable response compression diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index bc9d201..ba3f0ea 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -21,7 +21,7 @@ pagination.items_per_page=10 jwt.secret=qweernadnamdn19820918209!#ajhad jwt.expiration=3600 -api.version=2020-06-14 +api.version=2020-07-29 api.key="FX001-FREE" #Enable response compression @@ -33,8 +33,12 @@ server.compression.min-response-size=2048 #Mime types that should be compressed server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain,application/javascript,text/css -#Configuring Spring Boot Admin Server -spring.boot.admin.client.url=http://localhost:9090 +#Configuring Spring Boot Admin Client +server.url=http://localhost +server.admin.port=9090 +server.client.port=8080 +spring.boot.admin.client.url=${server.url}:${server.admin.port} +spring.boot.admin.client.instance.serviceBaseUrl=${server.url}:${server.client.port} management.endpoints.web.base-path=/manage management.endpoints.web.exposure.include=*