Benutzerdefinierte Annotationen funktionieren bei Spring Beans nichtJava

Java-Forum
Guest
 Benutzerdefinierte Annotationen funktionieren bei Spring Beans nicht

Post by Guest »

Ich habe meine neue benutzerdefinierte Anmerkung @MyCustomAnnotation erstellt:

Code: Select all

@Target({ElementType.METHOD, ElementType.TYPE, ElementType.FIELD})
@Retention(RUNTIME)
public @interface MyCustomAnnotation {
}
Ich habe diese Annotation auf Komponente und Bean angewendet. Hier ist der Code,

Code: Select all

@MyCustomAnnotation
@Component
public class CoreBusinessLogicHandler implements GenericHandler {
// some business logic
}
Und

Code: Select all

@Configuration
public class BusinessConfig {

@Autowired
private CoreIntegrationComponent coreIntegrationComponent;

@MyCustomAnnotation
@Bean(name = INCOMING_PROCESS_CHANNEL)
public MessageChannel incomingProcessChannel() {
return coreIntegrationComponent.amqpChannel(INCOMING_PROCESS_CHANNEL);
}

//some other configurations
}
Jetzt möchte ich, dass alle Beans mit @MyCustomAnnotation annotiert werden. Hier ist der Code:

Code: Select all

import org.springframework.context.ApplicationContext;

@Configuration
public class ChannelConfig {

@Autowired
private ApplicationContext applicationContext;

public List getRecipientChannel(CoreIntegrationComponent coreIntegrationComponent) {

String[] beanNamesForAnnotation = applicationContext.getBeanNamesForAnnotation(MyCustomAnnotation.class);
//Here in output I am getting bean name for CoreBusinessLogicHandler Only.

}
}
Meine Frage ist, warum ich kein Bean mit dem Namen „INCOMING_PROCESS_CHANNEL“ erhalte, da es @MyCustomAnnotation hat? Welche Codeänderungen sollte ich vornehmen, wenn ich eine Bean mit dem Namen „INCOMING_PROCESS_CHANNEL“ erhalten möchte?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post