I have below annotation.
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Import(MyBeanInitializer.class)
public @interface MyAnnotation {
String clientType() default "" ;
}
And I have a Bean initialiser component as below
@Configuration
public class MyBeanInitializer {
@Bean() // trigger this when annoattion's value == "A"
public CommonBean firstBean() {
return new BeanA;
}
@Bean() // trigger this when annoattion's value == "B"
public CommonBean firstBean() {
return new BeanB;
}
}
My Commoin interface for BeanA and BeanB
public interface CommonBean {
void doSomething();
}
And my Two Implementations are
@Component()
public class BeanA implements CommonBean {
@Overrid
public void doSomething (){
// implementation here
}
}
@Component()
public class BeanB implements CommonBean {
@Overrid
public void doSomething (){
// implementation here
}
}
I need to use above as an library for another Spring Boot project. In that project I annotate Application.java with @MyAnnotation(clientType="web") and then I inject BeanA or BeanB to a class inside that project by using constructor Injection.
What is the mechanism to initialise beans by looking at the values passed through the annotation?
BeanAandBeanB, do you plan to move them to a single Interface? It's not clear what exactly you want to do - iam.CarrotMyAnnotationin your example. - Sotirios Delimanolis@Conditionalfor conditional definitions. - Sotirios DelimanolisBeanAandBeanBare two differentDataTypescan you please share what exactly are you trying to do? You've sharedThe Howbut we want to knowThe Why. What is it that you're trying to achieve? Maybe give an example of what the condition would be and what what would happen when the condition istrueand what would happen if the condition isfalse. How would you use the two differentdatatypes? Is there a commoninterfaceyou've declared that you haven't mentioned? - iam.Carrot