private Object getBeanFromSpringContext(String beanName, Injectee injectee, final boolean required) { try { DependencyDescriptor dependencyDescriptor = createSpringDependencyDescriptor(injectee); Set<String> autowiredBeanNames = new HashSet<>(1); autowiredBeanNames.add(beanName); return ctx.getAutowireCapableBeanFactory().resolveDependency(dependencyDescriptor, null, autowiredBeanNames, null); } catch (NoSuchBeanDefinitionException e) { if (required) { LOGGER.warning(e.getMessage()); throw e; } return null; } }
@Test public void getBeanByTypeAmbiguityRaisesException() { ApplicationContext context = new AnnotationConfigApplicationContext(TwoTestBeanConfig.class); try { context.getBean(TestBean.class); } catch (NoSuchBeanDefinitionException ex) { assertThat(ex.getMessage(), allOf( containsString("No qualifying bean of type '" + TestBean.class.getName() + "'"), containsString("tb1"), containsString("tb2") ) ); } }
@Test public void getBeanByTypeRaisesNoSuchBeanDefinitionException() { ApplicationContext context = new AnnotationConfigApplicationContext(Config.class); // attempt to retrieve a bean that does not exist Class<?> targetType = Pattern.class; try { context.getBean(targetType); fail("Should have thrown NoSuchBeanDefinitionException"); } catch (NoSuchBeanDefinitionException ex) { assertThat(ex.getMessage(), containsString(format("No qualifying bean of type '%s'", targetType.getName()))); } }
@Test public void missingAuthenticationManagerGivesSensibleErrorMessage() { try { setContext("<http auto-config='true' />"); fail(); } catch (BeanCreationException e) { Throwable cause = ultimateCause(e); assertThat(cause instanceof NoSuchBeanDefinitionException).isTrue(); NoSuchBeanDefinitionException nsbe = (NoSuchBeanDefinitionException) cause; assertThat(nsbe.getBeanName()).isEqualTo(BeanIds.AUTHENTICATION_MANAGER); assertThat(nsbe.getMessage()).endsWith( AuthenticationManagerFactoryBean.MISSING_BEAN_ERROR_MESSAGE); } }
} catch (NoSuchBeanDefinitionException e) { if (logger.isDebugEnabled()) { logger.debug(e.getMessage(), e);
@Override public Object postProcess(Object bean, String beanName, Method method, List<Annotation> annotations) { String channelName = MessagingAnnotationUtils .resolveAttribute(annotations, AnnotationUtils.VALUE, String.class); Assert.hasText(channelName, "The channel ('value' attribute of @InboundChannelAdapter) can't be empty."); MessageSource<?> messageSource = null; try { messageSource = createMessageSource(bean, beanName, method); } catch (NoSuchBeanDefinitionException e) { if (this.logger.isDebugEnabled()) { this.logger.debug("Skipping endpoint creation; " + e.getMessage() + "; perhaps due to some '@Conditional' annotation."); } return null; } SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); adapter.setOutputChannelName(channelName); adapter.setSource(messageSource); configurePollingEndpoint(adapter, annotations); return adapter; }
private void initNoBeanCaseInfo() { if (noBeanCaseInfo != null) return; try { applicationContext.getBean(hashCode() + ""); } catch (NoSuchBeanDefinitionException e) { noBeanCaseInfo = e.getMessage(); } }
public <T> T getBean(String name) { try { return (T) applicationContext.getBean(name); } catch (NoSuchBeanDefinitionException e) { String message = e.getMessage(); if (message.equals(noBeanCaseInfo.replace(hashCode() + "", name))) { if (parent != null) { return (T) parent.getBean(name); } } throw e; } }
public <T> T getBean(String name, Class<T> clazz) { try { return (T) applicationContext.getBean(name, clazz); } catch (NoSuchBeanDefinitionException e) { String message = e.getMessage(); if (message.equals(noBeanCaseInfo.replace(hashCode() + "", name))) { if (parent != null) { return parent.getBean(name, clazz); } } throw e; } }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { PaymentDatabaseProperties properties = null; try { properties = (PaymentDatabaseProperties) context.getBeanFactory().getBean("paymentDatabaseProperties"); } catch (NoSuchBeanDefinitionException e) { LOGGER.warn(e.getMessage()); } return (properties != null); } }
private Object getBeanFromSpringContext(String beanName, Injectee injectee, final boolean required) { try { DependencyDescriptor dependencyDescriptor = createSpringDependencyDescriptor(injectee); Set<String> autowiredBeanNames = new HashSet<>(1); autowiredBeanNames.add(beanName); return ctx.getAutowireCapableBeanFactory().resolveDependency(dependencyDescriptor, null, autowiredBeanNames, null); } catch (NoSuchBeanDefinitionException e) { if (required) { LOGGER.warning(e.getMessage()); throw e; } return null; } }
/** * Gets string value resolver. * * @param applicationContext the application context * @return the string value resolver */ public static StringValueResolver prepScheduledAnnotationBeanPostProcessor(final ApplicationContext applicationContext) { val resolver = new CasEmbeddedValueResolver(applicationContext); try { val sch = applicationContext.getBean(ScheduledAnnotationBeanPostProcessor.class); sch.setEmbeddedValueResolver(resolver); } catch (final NoSuchBeanDefinitionException e) { LOGGER.warn("Unable to locate [ScheduledAnnotationBeanPostProcessor] as a bean. Support for duration syntax (i.e. PT2S) may not be available"); LOGGER.trace(e.getMessage(), e); } return resolver; } }
if (e.getMessage().startsWith("Invalid bean definition with name ") && e.getMessage() .contains("Could not resolve placeholder")) else if (e.getMessage().startsWith("Invalid bean definition with name. "))
@Override public void sessionDestroyed(HttpSessionEvent se) { if (ApplicationContextProvider.isConfigured()){ try { ApplicationContextProvider.get().getBean(WicketSessionCacheManager.class).clearCache(); } catch (org.springframework.beans.factory.NoSuchBeanDefinitionException e) { getLogger().warn(e.getMessage(), e); } } } }
@Override public void sessionDestroyed(HttpSessionEvent se) { if (ApplicationContextProvider.isConfigured()){ try { ApplicationContextProvider.get().getBean(WicketSessionCacheManager.class).clearCache(); } catch (org.springframework.beans.factory.NoSuchBeanDefinitionException e) { getLogger().warn(e.getMessage(), e); } } } }
@Override public void sessionDestroyed(HttpSessionEvent se) { if (ApplicationContextProvider.isConfigured()){ try { ApplicationContextProvider.get().getBean(WicketSessionCacheManager.class).clearCache(); } catch (org.springframework.beans.factory.NoSuchBeanDefinitionException e) { getLogger().warn(e.getMessage(), e); } } } }
} catch (NoSuchBeanDefinitionException e) { if (logger.isDebugEnabled()) { logger.debug(e.getMessage(), e);
private JMSServices(NamingProvider namingProvider, JmsProvider jmsProvider) { this.namingProvider = namingProvider; this.jmsProvider = jmsProvider; logger = LoggerUtil.getStandardLogger(); queueCache = new Hashtable<String, Queue>(); queueConnFactoryCache = new Hashtable<String, QueueConnectionFactory>(); topicConnFactoryCache = new Hashtable<String, TopicConnectionFactory>(); try { mdwMessageProducer = (MessageProducer) SpringAppContext.getInstance() .getBean(SpringAppContext.MDW_SPRING_MESSAGE_PRODUCER); } catch (NoSuchBeanDefinitionException ex) { if (logger.isMdwDebugEnabled()) logger.severeException(ex.getMessage(), ex); } catch (Exception ex) { logger.severeException(ex.getMessage(), ex); } }
@Override public Object postProcess(Object bean, String beanName, Method method, List<Annotation> annotations) { String channelName = MessagingAnnotationUtils .resolveAttribute(annotations, AnnotationUtils.VALUE, String.class); Assert.hasText(channelName, "The channel ('value' attribute of @InboundChannelAdapter) can't be empty."); MessageSource<?> messageSource = null; try { messageSource = createMessageSource(bean, beanName, method); } catch (NoSuchBeanDefinitionException e) { if (this.logger.isDebugEnabled()) { this.logger.debug("Skipping endpoint creation; " + e.getMessage() + "; perhaps due to some '@Conditional' annotation."); } return null; } SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); adapter.setOutputChannelName(channelName); adapter.setSource(messageSource); configurePollingEndpoint(adapter, annotations); return adapter; }
logger.debug(e.getMessage(), e);