educative.io

Educative

Qualifier is not working for me

I am in lesson 6 part which introduced qualifier. I have added qualifier in classes as follows:

CollaborativeFilter.java
package io.datajek.spring.basics.movierecommendersystem.lesson6;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

@Component
@Qualifier("CF")
public class CollaborativeFilter implements Filter {
    public String[] getRecommendations(String movie) {
        //logic of collaborative filter
        return new String[] { };
    }
}

ContentBasedFilter.java
package io.datajek.spring.basics.movierecommendersystem.lesson6;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

@Component
@Qualifier("CBF")
public class ContentBasedFilter implements Filter {
    public String[] getRecommendations(String movie) {
        //logic of content based filter
        return new String[] {"Happy Feet", "Ice Age", "Shark Tale"};
    }
}

RecommenderImplementation.java
package io.datajek.spring.basics.movierecommendersystem.lesson6;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

@Component
public class RecommenderImplementation {
    @Autowired
    @Qualifier("CF")
    private Filter filter;

    public RecommenderImplementation(Filter filter) {
        super();
        this.filter = filter;
    }
    public String[] recommendMovies (String movie) {
        //print the name of interface implementation being used
        System.out.println("Name of the filter in use: " + filter.toString() + "\n");
        //use passed filter to find similar movies
        String[] results = filter.getRecommendations("Finding Dory");
        //return the results
        return results;
    }
}

I believe I am using Qualifier correctly. Still I am getting below error. Could you tell why?


APPLICATION FAILED TO START


Description:

Parameter 0 of constructor in io.datajek.spring.basics.movierecommendersystem.lesson6.RecommenderImplementation required a single bean, but 2 were found:
- CF: defined in file [D:\Crio\Educative\movie-recommender-system\movie-recommender-system\target\classes\io\datajek\spring\basics\movierecommendersystem\lesson6\CollaborativeFilter.class]
- CBF: defined in file [D:\Crio\Educative\movie-recommender-system\movie-recommender-system\target\classes\io\datajek\spring\basics\movierecommendersystem\lesson6\ContentBasedFilter.class]

Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

Process finished with exit code 1