@@ -496,15 +496,14 @@ private RabbitListenerContainerFactory<?> resolveContainerFactory(RabbitListener
496
496
RabbitListenerContainerFactory <?> factory = null ;
497
497
String containerFactoryBeanName = resolve (rabbitListener .containerFactory ());
498
498
if (StringUtils .hasText (containerFactoryBeanName )) {
499
- Assert . state ( this . beanFactory != null , "BeanFactory must be set to obtain container factory by bean name" );
499
+ assertBeanFactory ( );
500
500
try {
501
501
factory = this .beanFactory .getBean (containerFactoryBeanName , RabbitListenerContainerFactory .class );
502
502
}
503
503
catch (NoSuchBeanDefinitionException ex ) {
504
- throw new BeanInitializationException ("Could not register rabbit listener endpoint on ["
505
- + factoryTarget + "] for bean " + beanName + ", no "
506
- + RabbitListenerContainerFactory .class .getSimpleName () + " with id '"
507
- + containerFactoryBeanName + "' was found in the application context" , ex );
504
+ throw new BeanInitializationException (
505
+ noBeanFoundMessage (factoryTarget , beanName , containerFactoryBeanName ,
506
+ RabbitListenerContainerFactory .class ), ex );
508
507
}
509
508
}
510
509
return factory ;
@@ -515,36 +514,44 @@ private void resolveExecutor(MethodRabbitListenerEndpoint endpoint, RabbitListen
515
514
516
515
String execBeanName = resolve (rabbitListener .executor ());
517
516
if (StringUtils .hasText (execBeanName )) {
518
- Assert . state ( this . beanFactory != null , "BeanFactory must be set to obtain container factory by bean name" );
517
+ assertBeanFactory ( );
519
518
try {
520
519
endpoint .setTaskExecutor (this .beanFactory .getBean (execBeanName , TaskExecutor .class ));
521
520
}
522
521
catch (NoSuchBeanDefinitionException ex ) {
523
- throw new BeanInitializationException ("Could not register rabbit listener endpoint on ["
524
- + execTarget + "] for bean " + beanName + ", no 'TaskExecutor' with id '"
525
- + execBeanName + "' was found in the application context" , ex );
522
+ throw new BeanInitializationException (
523
+ noBeanFoundMessage (execTarget , beanName , execBeanName , TaskExecutor .class ), ex );
526
524
}
527
525
}
528
526
}
529
527
530
- @ SuppressWarnings ("unchecked" )
531
528
private void resolvePostProcessor (MethodRabbitListenerEndpoint endpoint , RabbitListener rabbitListener ,
532
529
Object target , String beanName ) {
533
530
534
531
String ppBeanName = resolve (rabbitListener .replyPostProcessor ());
535
532
if (StringUtils .hasText (ppBeanName )) {
536
- Assert . state ( this . beanFactory != null , "BeanFactory must be set to obtain container factory by bean name" );
533
+ assertBeanFactory ( );
537
534
try {
538
535
endpoint .setReplyPostProcessor (this .beanFactory .getBean (ppBeanName , ReplyPostProcessor .class ));
539
536
}
540
537
catch (NoSuchBeanDefinitionException ex ) {
541
- throw new BeanInitializationException ("Could not register rabbit listener endpoint on ["
542
- + target + "] for bean " + beanName + ", no 'ReplyPostProcessor' with id '"
543
- + ppBeanName + "' was found in the application context" , ex );
538
+ throw new BeanInitializationException (
539
+ noBeanFoundMessage (target , beanName , ppBeanName , ReplyPostProcessor .class ), ex );
544
540
}
545
541
}
546
542
}
547
543
544
+ protected void assertBeanFactory () {
545
+ Assert .state (this .beanFactory != null , "BeanFactory must be set to obtain container factory by bean name" );
546
+ }
547
+
548
+ protected String noBeanFoundMessage (Object target , String listenerBeanName , String requestedBeanName ,
549
+ Class <?> expectedClass ) {
550
+ return "Could not register rabbit listener endpoint on ["
551
+ + target + "] for bean " + listenerBeanName + ", no '" + expectedClass .getSimpleName () + "' with id '"
552
+ + requestedBeanName + "' was found in the application context" ;
553
+ }
554
+
548
555
private String getEndpointId (RabbitListener rabbitListener ) {
549
556
if (StringUtils .hasText (rabbitListener .id ())) {
550
557
return resolve (rabbitListener .id ());
0 commit comments