Search in sources :

Example 31 with NoSuchBeanDefinitionException

use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project cxf by apache.

the class ConfigurerImpl method configureBean.

public synchronized void configureBean(String bn, Object beanInstance, boolean checkWildcards) {
    if (null == appContexts) {
        return;
    }
    if (null == bn) {
        bn = getBeanName(beanInstance);
    }
    if (null == bn) {
        return;
    }
    if (checkWildcards) {
        configureWithWildCard(bn, beanInstance);
    }
    final String beanName = bn;
    setBeanWiringInfoResolver(new BeanWiringInfoResolver() {

        public BeanWiringInfo resolveWiringInfo(Object instance) {
            if (!"".equals(beanName)) {
                return new BeanWiringInfo(beanName);
            }
            return null;
        }
    });
    for (ApplicationContext appContext : appContexts) {
        if (appContext.containsBean(bn)) {
            this.setBeanFactory(appContext.getAutowireCapableBeanFactory());
        }
    }
    try {
        // this can leak memory
        if (beanFactory instanceof AbstractBeanFactory) {
            ((AbstractBeanFactory) beanFactory).getMergedBeanDefinition(bn);
        }
        super.configureBean(beanInstance);
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Successfully performed injection.");
        }
    } catch (NoSuchBeanDefinitionException ex) {
        // incorrect bean ids
        if (LOG.isLoggable(Level.FINE)) {
            LOG.log(Level.FINE, "NO_MATCHING_BEAN_MSG", beanName);
        }
    }
}
Also used : BeanWiringInfo(org.springframework.beans.factory.wiring.BeanWiringInfo) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) AbstractBeanFactory(org.springframework.beans.factory.support.AbstractBeanFactory) BeanWiringInfoResolver(org.springframework.beans.factory.wiring.BeanWiringInfoResolver) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException)

Example 32 with NoSuchBeanDefinitionException

use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project engine by craftercms.

the class BeanDefinitionUtils method createBeanDefinitionFromOriginal.

/**
 * Creates a bean definition for the specified bean name. If the parent context of the current context contains a
 * bean definition with the same name, the definition is created as a bean copy of the parent definition. This
 * method is useful for config parsers that want to create a bean definition from configuration but also want to
 * retain the default properties of the original bean.
 *
 * @param applicationContext    the current application context
 * @param beanName
 * @return the bean definition
 */
public static BeanDefinition createBeanDefinitionFromOriginal(ApplicationContext applicationContext, String beanName) {
    ApplicationContext parentContext = applicationContext.getParent();
    BeanDefinition parentDefinition = null;
    if (parentContext != null && parentContext.getAutowireCapableBeanFactory() instanceof ConfigurableListableBeanFactory) {
        ConfigurableListableBeanFactory parentBeanFactory = (ConfigurableListableBeanFactory) parentContext.getAutowireCapableBeanFactory();
        try {
            parentDefinition = parentBeanFactory.getBeanDefinition(beanName);
        } catch (NoSuchBeanDefinitionException e) {
        }
    }
    if (parentDefinition != null) {
        return new GenericBeanDefinition(parentDefinition);
    } else {
        return new GenericBeanDefinition();
    }
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) ApplicationContext(org.springframework.context.ApplicationContext) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 33 with NoSuchBeanDefinitionException

use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project leopard by tanhaichao.

the class LeopardHandlerMapping method initApplicationContext.

@Override
protected void initApplicationContext(ApplicationContext context) throws BeansException {
    try {
        Redis redis = (Redis) context.getBean("sessionRedis");
        StoreRedisImpl.setRedis(redis);
    } catch (NoSuchBeanDefinitionException e) {
        logger.warn("没有配置sessionRedis,不启用分布式session.");
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    super.initApplicationContext(context);
    requestMappingInfoBuilder = new RequestMappingInfoBuilderImpl(context);
}
Also used : Redis(io.leopard.redis.Redis) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) BeansException(org.springframework.beans.BeansException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) RequestMappingInfoBuilderImpl(io.leopard.vhost.RequestMappingInfoBuilderImpl)

Example 34 with NoSuchBeanDefinitionException

use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project jersey by jersey.

the class AutowiredInjectResolver method getBeanFromSpringContext.

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;
    }
}
Also used : DependencyDescriptor(org.springframework.beans.factory.config.DependencyDescriptor) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) HashSet(java.util.HashSet)

Example 35 with NoSuchBeanDefinitionException

use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project spring-framework by spring-projects.

the class MockHttpServletRequestBuilder method getFlashMapManager.

private FlashMapManager getFlashMapManager(MockHttpServletRequest request) {
    FlashMapManager flashMapManager = null;
    try {
        ServletContext servletContext = request.getServletContext();
        WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
        flashMapManager = wac.getBean(DispatcherServlet.FLASH_MAP_MANAGER_BEAN_NAME, FlashMapManager.class);
    } catch (IllegalStateException ex) {
    // ignore
    } catch (NoSuchBeanDefinitionException ex) {
    // ignore
    }
    return (flashMapManager != null ? flashMapManager : new SessionFlashMapManager());
}
Also used : SessionFlashMapManager(org.springframework.web.servlet.support.SessionFlashMapManager) FlashMapManager(org.springframework.web.servlet.FlashMapManager) ServletContext(javax.servlet.ServletContext) SessionFlashMapManager(org.springframework.web.servlet.support.SessionFlashMapManager) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Aggregations

NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)71 Test (org.junit.Test)27 BeanCreationException (org.springframework.beans.factory.BeanCreationException)18 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)15 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)14 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)9 HashMap (java.util.HashMap)8 EventBus (org.apache.cloudstack.framework.events.EventBus)8 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)8 SimpleDateFormat (java.text.SimpleDateFormat)7 Date (java.util.Date)7 EventBusException (org.apache.cloudstack.framework.events.EventBusException)7 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)7 ConfigurableBeanFactory (org.springframework.beans.factory.config.ConfigurableBeanFactory)6 Method (java.lang.reflect.Method)5 BeanFactory (org.springframework.beans.factory.BeanFactory)5 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)5 ApplicationContext (org.springframework.context.ApplicationContext)5 ArrayList (java.util.ArrayList)4 Account (com.cloud.user.Account)3