@@ -496,15 +496,14 @@ private RabbitListenerContainerFactory<?> resolveContainerFactory(RabbitListener
496496 RabbitListenerContainerFactory <?> factory = null ;
497497 String containerFactoryBeanName = resolve (rabbitListener .containerFactory ());
498498 if (StringUtils .hasText (containerFactoryBeanName )) {
499- Assert . state ( this . beanFactory != null , "BeanFactory must be set to obtain container factory by bean name" );
499+ assertBeanFactory ( );
500500 try {
501501 factory = this .beanFactory .getBean (containerFactoryBeanName , RabbitListenerContainerFactory .class );
502502 }
503503 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 );
508507 }
509508 }
510509 return factory ;
@@ -515,36 +514,44 @@ private void resolveExecutor(MethodRabbitListenerEndpoint endpoint, RabbitListen
515514
516515 String execBeanName = resolve (rabbitListener .executor ());
517516 if (StringUtils .hasText (execBeanName )) {
518- Assert . state ( this . beanFactory != null , "BeanFactory must be set to obtain container factory by bean name" );
517+ assertBeanFactory ( );
519518 try {
520519 endpoint .setTaskExecutor (this .beanFactory .getBean (execBeanName , TaskExecutor .class ));
521520 }
522521 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 );
526524 }
527525 }
528526 }
529527
530- @ SuppressWarnings ("unchecked" )
531528 private void resolvePostProcessor (MethodRabbitListenerEndpoint endpoint , RabbitListener rabbitListener ,
532529 Object target , String beanName ) {
533530
534531 String ppBeanName = resolve (rabbitListener .replyPostProcessor ());
535532 if (StringUtils .hasText (ppBeanName )) {
536- Assert . state ( this . beanFactory != null , "BeanFactory must be set to obtain container factory by bean name" );
533+ assertBeanFactory ( );
537534 try {
538535 endpoint .setReplyPostProcessor (this .beanFactory .getBean (ppBeanName , ReplyPostProcessor .class ));
539536 }
540537 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 );
544540 }
545541 }
546542 }
547543
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+
548555 private String getEndpointId (RabbitListener rabbitListener ) {
549556 if (StringUtils .hasText (rabbitListener .id ())) {
550557 return resolve (rabbitListener .id ());
0 commit comments