我有以下注释。
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Import(MyBeanInitializer.class)
public @interface MyAnnotation {
String clientType() default "" ;
}
而且我有一个如下所示的Bean初始化程序组件
@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;
}
}
我的BeanA和BeanB的Commoin接口
public interface CommonBean {
void doSomething();
}
我的两个实现是>
或BeanB注入该项目内的类。@Component() public class BeanA implements CommonBean { @Overrid public void doSomething (){ // implementation here } } @Component() public class BeanB implements CommonBean { @Overrid public void doSomething (){ // implementation here } }
我需要将上面用作另一个Spring Boot项目的库。在该项目中,我用
Application.java
注释了@MyAnnotation(clientType="web")
,然后使用构造函数Injection将BeanA
通过查看通过注释传递的值来初始化bean的机制是什么?
我有以下注释。 @Retention(RetentionPolicy.RUNTIME)@Target({ElementType.TYPE})@Import(MyBeanInitializer.class)public @interface MyAnnotation {字符串clientType()默认“”; }而且我...
请勿为此使用注释值。