diff --git a/src/main/java/guru/springframework/sfgdi/controllers/PetController.java b/src/main/java/guru/springframework/sfgdi/controllers/PetController.java index 6810ff49e6..ad358c3ea8 100644 --- a/src/main/java/guru/springframework/sfgdi/controllers/PetController.java +++ b/src/main/java/guru/springframework/sfgdi/controllers/PetController.java @@ -1,15 +1,22 @@ package guru.springframework.sfgdi.controllers; import guru.springframework.sfgdi.services.PetService; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; /** * Created by jt on 12/28/19. */ +@Controller public class PetController { private final PetService petService; - public String whichPetIsTheBest(){ + public PetController(@Qualifier("petChooserService") PetService petService) { + this.petService = petService; + } + + public String whichPetIsTheBest() { return petService.getPetType(); } } diff --git a/src/main/java/guru/springframework/sfgdi/services/CatPetService.java b/src/main/java/guru/springframework/sfgdi/services/CatPetService.java index 097cf4563d..8498d393fb 100644 --- a/src/main/java/guru/springframework/sfgdi/services/CatPetService.java +++ b/src/main/java/guru/springframework/sfgdi/services/CatPetService.java @@ -1,11 +1,13 @@ package guru.springframework.sfgdi.services; +import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Service; /** * Created by jt on 12/28/19. */ -@Service("cat") +@Profile("cat") +@Service("petChooserService") public class CatPetService implements PetService { @Override public String getPetType() { diff --git a/src/main/java/guru/springframework/sfgdi/services/DogPetService.java b/src/main/java/guru/springframework/sfgdi/services/DogPetService.java index 9d8547e9a2..4b057aeb20 100644 --- a/src/main/java/guru/springframework/sfgdi/services/DogPetService.java +++ b/src/main/java/guru/springframework/sfgdi/services/DogPetService.java @@ -1,12 +1,15 @@ package guru.springframework.sfgdi.services; import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Service; /** * Created by jt on 12/28/19. */ -@Profile({"dog", "default"}) -public class DogPetService { +@Profile({"dog","default"}) +@Service("petChooserService") +public class DogPetService implements PetService { + @Override public String getPetType(){ return "Dogs are the best!"; } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f925173f32..19785710ef 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1 @@ -#spring.profiles.active=EN +spring.profiles.active=cat, EN