[FIXED] Wrong profile is active


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 ---");

public class PetController {

    public PetController(PetService petService) {
        this.petService = petService;

    private final PetService petService;

    public String whichPetIsTheBest(){
        return petService.getPetType();

public interface PetService {

    String getPetType();

public class CatPetService implements PetService {
    public String getPetType() {
        return "Cats Are the Best!";

@Profile({"dog", "default"})
public class DogPetService implements PetService {
    public String getPetType(){
        return "Dogs are the best!";




--- The Best Pet is ---
Cats Are the Best!

I don’t understand why cats are here. I can even comment the properties out, but cats are still here. I would like to see dogs.

What can I try next?


It looks like the DogService is not a bean. So in the end you only have a single bean (CatService) and this one will be picked all the time.

Answered By – Loading

Answer Checked By – Jay B. (FixeMe Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *