2020-03-25

Spring @Named

If you would like to use a qualified name for the dependency that should be injected, you should use the @Named annotation, as the following example shows:

import javax.inject.Inject;
import javax.inject.Named;

public class SimpleMovieLister {

    private MovieFinder movieFinder;

    @Inject
    public void setMovieFinder(@Named("main") MovieFinder movieFinder) {
        this.movieFinder = movieFinder;
    }

    // ...
}

No comments:

Post a Comment