From a079a97c1e300a9d3ed10820e230fae74054bd85 Mon Sep 17 00:00:00 2001 From: Gabriel Magioli Date: Fri, 29 Dec 2023 16:08:45 -0300 Subject: [PATCH] Refactor: Use environment variables for URLs and @Autowired for injection Instead of hardcoding URLs for owners/createOrUpdateOwnerForm and pets/createOrUpdatePetForm in the code, introduce environment variables for these values. Removed the static final type to allow injection. Also, replaced constructor injection with @Autowired annotation for OwnerRepository to reduce lines of code. --- .../samples/petclinic/owner/OwnerController.java | 2 ++ .../springframework/samples/petclinic/owner/PetController.java | 2 ++ src/main/resources/application.properties | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java b/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java index 25417e968..164d05f42 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java @@ -32,6 +32,8 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import jakarta.validation.Valid; diff --git a/src/main/java/org/springframework/samples/petclinic/owner/PetController.java b/src/main/java/org/springframework/samples/petclinic/owner/PetController.java index 4334ece14..4e5d097c7 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/PetController.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/PetController.java @@ -29,6 +29,8 @@ import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import jakarta.validation.Valid; diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index df874a090..96e72f438 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -26,4 +26,4 @@ spring.web.resources.cache.cachecontrol.max-age=12h # Environment Variables views.owner.createOrUpdateForm=owners/createOrUpdateOwnerForm -views.pets.createOrUpdateForm=pets/createOrUpdatePetForm \ No newline at end of file +views.pets.createOrUpdateForm=pets/createOrUpdatePetForm