Skip to content

Commit

Permalink
adding pet controller, broken example for assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
springframeworkguru committed Dec 28, 2019
1 parent ec3faa3 commit e3d002f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public class SfgDiApplication {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(SfgDiApplication.class, args);

PetController petController = ctx.getBean("petController", PetController.class);
System.out.println("--- The Best Pet is ---");
System.out.println(petController.whichPetIsTheBest());

I18nController i18nController = (I18nController) ctx.getBean("i18nController");
System.out.println(i18nController.sayHello());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package guru.springframework.sfgdi.controllers;

import guru.springframework.sfgdi.services.PetService;

/**
* Created by jt on 12/28/19.
*/
public class PetController {

private final PetService petService;

public String whichPetIsTheBest(){
return petService.getPetType();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package guru.springframework.sfgdi.services;

import org.springframework.stereotype.Service;

/**
* Created by jt on 12/28/19.
*/
@Service("cat")
public class CatPetService implements PetService {
@Override
public String getPetType() {
return "Cats Are the Best!";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package guru.springframework.sfgdi.services;

import org.springframework.context.annotation.Profile;

/**
* Created by jt on 12/28/19.
*/
@Profile({"dog", "default"})
public class DogPetService {
public String getPetType(){
return "Dogs are the best!";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package guru.springframework.sfgdi.services;

/**
* Created by jt on 12/28/19.
*/
public interface PetService {

String getPetType();
}

0 comments on commit e3d002f

Please sign in to comment.