【发布时间】:2018-02-06 11:07:47
【问题描述】:
我创建了新的自定义注释@MyCustomAnnotation
@Target({ElementType.METHOD, ElementType.TYPE, ElementType.FIELD})
@Retention(RUNTIME)
public @interface MyCustomAnnotation{
}
我在组件和 bean 上应用了该注释。这是代码,
@MyCustomAnnotation
@Component
public class CoreBussinessLogicHandler implements GenericHandler<BussinessFile> {
//some bussiness logic
}
和
@Configuration
public class BussinessConfig {
@Autowired
private CoreIntegrationComponent coreIntegrationComponent;
@MyCustomAnnotation
@Bean(name = INCOMING_PROCESS_CHANNEL)
public MessageChannel incomingProcessChannel() {
return coreIntegrationComponent.amqpChannel(INCOMING_PROCESS_CHANNEL);
}
//some other configurations
}
现在我想要使用@MyCustomAnnotation 注释的所有bean。所以这里是代码,
import org.springframework.context.ApplicationContext;
@Configuration
public class ChannelConfig {
@Autowired
private ApplicationContext applicationContext;
public List<MessageChannel> getRecipientChannel(CoreIntegrationComponent coreIntegrationComponent) {
String[] beanNamesForAnnotation = applicationContext.getBeanNamesForAnnotation(MyCustomAnnotation.class);
//Here in output I am getting bean name for CoreBussinessLogicHandler Only.
}
}
我的问题是为什么我没有得到名称为 'INCOMING_PROCESS_CHANNEL' 的 Bean,因为它有 @MyCustomAnnotation ?如果我想获得名称为“INCOMING_PROCESS_CHANNEL”的 bean,我应该做哪些代码更改?
【问题讨论】:
标签: java spring spring-mvc spring-integration spring-annotations