defima tech
defima tech

Reputation: 21

Can i inject bean depend on package?

Can i inject bean depend on package ? package A inject AImpl, pakage B inject BImpl. I can't using qualifier because class injected interface is library.

Upvotes: 1

Views: 55

Answers (1)

Aniket Sahrawat
Aniket Sahrawat

Reputation: 12937

Probably not! But you can use @Qualifier to pick the specific type of bean you desire. Eg:

@Bean("hi") String h1() {return "hi";}
@Bean("hello") String h2() {return "hello";}

@Bean ApplicationRunner runner(@Qualifier("hi") String str) {
    return args -> {
        System.out.println(str);
    };
}

Upvotes: 1

Related Questions