Search in sources :

Example 46 with BeanDefinitionStoreException

use of org.springframework.beans.factory.BeanDefinitionStoreException in project spring-integration by spring-projects.

the class PublisherRegistrar method registerBeanDefinitions.

@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    Map<String, Object> annotationAttributes = importingClassMetadata.getAnnotationAttributes(EnablePublisher.class.getName());
    String value = (annotationAttributes == null ? (String) AnnotationUtils.getDefaultValue(EnablePublisher.class) : (String) annotationAttributes.get("value"));
    if (!registry.containsBeanDefinition(IntegrationContextUtils.PUBLISHER_ANNOTATION_POSTPROCESSOR_NAME)) {
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(PublisherAnnotationBeanPostProcessor.class).setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        if (StringUtils.hasText(value)) {
            builder.addPropertyValue("defaultChannelName", value);
            if (logger.isInfoEnabled()) {
                logger.info("Setting '@Publisher' default-output-channel to '" + value + "'.");
            }
        }
        registry.registerBeanDefinition(IntegrationContextUtils.PUBLISHER_ANNOTATION_POSTPROCESSOR_NAME, builder.getBeanDefinition());
    } else {
        BeanDefinition beanDefinition = registry.getBeanDefinition(IntegrationContextUtils.PUBLISHER_ANNOTATION_POSTPROCESSOR_NAME);
        MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();
        PropertyValue defaultChannelPropertyValue = propertyValues.getPropertyValue("defaultChannelName");
        if (StringUtils.hasText(value)) {
            if (defaultChannelPropertyValue == null) {
                propertyValues.addPropertyValue("defaultChannelName", value);
                if (logger.isInfoEnabled()) {
                    logger.info("Setting '@Publisher' default-output-channel to '" + value + "'.");
                }
            } else if (!value.equals(defaultChannelPropertyValue.getValue())) {
                throw new BeanDefinitionStoreException("When more than one enable publisher definition " + "(@EnablePublisher or <annotation-config>)" + " is found in the context, they all must have the same 'default-publisher-channel' value.");
            }
        }
    }
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) PropertyValue(org.springframework.beans.PropertyValue) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) PublisherAnnotationBeanPostProcessor(org.springframework.integration.aop.PublisherAnnotationBeanPostProcessor)

Example 47 with BeanDefinitionStoreException

use of org.springframework.beans.factory.BeanDefinitionStoreException in project spring-integration by spring-projects.

the class XmlPayloadValidatingFilterParser method parseHandler.

@Override
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder filterBuilder = BeanDefinitionBuilder.genericBeanDefinition(FilterFactoryBean.class);
    IntegrationNamespaceUtils.setReferenceIfAttributeDefined(filterBuilder, element, "discard-channel");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(filterBuilder, element, "throw-exception-on-rejection");
    BeanDefinitionBuilder selectorBuilder = BeanDefinitionBuilder.genericBeanDefinition(XmlValidatingMessageSelector.class);
    String validator = element.getAttribute("xml-validator");
    String schemaLocation = element.getAttribute("schema-location");
    boolean validatorDefined = StringUtils.hasText(validator);
    boolean schemaLocationDefined = StringUtils.hasText(schemaLocation);
    if (validatorDefined == schemaLocationDefined) {
        throw new BeanDefinitionStoreException("Exactly one of 'xml-validator' or 'schema-location' is allowed on the 'validating-filter' element");
    }
    if (schemaLocationDefined) {
        selectorBuilder.addConstructorArgValue(schemaLocation);
        // it is a restriction with the default value of 'xml-schema' which
        // corresponds to 'http://www.w3.org/2001/XMLSchema'
        String schemaType = element.getAttribute("schema-type");
        selectorBuilder.addConstructorArgValue(schemaType);
    } else {
        selectorBuilder.addConstructorArgReference(validator);
    }
    IntegrationNamespaceUtils.setValueIfAttributeDefined(selectorBuilder, element, "throw-exception-on-rejection");
    IntegrationNamespaceUtils.setReferenceIfAttributeDefined(selectorBuilder, element, "xml-converter", "converter");
    filterBuilder.addPropertyValue("targetObject", selectorBuilder.getBeanDefinition());
    IntegrationNamespaceUtils.setValueIfAttributeDefined(filterBuilder, element, "send-timeout");
    return filterBuilder;
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException)

Example 48 with BeanDefinitionStoreException

use of org.springframework.beans.factory.BeanDefinitionStoreException in project ff4j by ff4j.

the class FF4jPropertiesPlaceHolderConfigurer method postProcessBeanFactory.

/**
 * {@inheritDoc}
 */
public final void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) {
    try {
        // 1) Retrieve properties from ff4j
        BeanDefinitionVisitor visitor = new PropertiesPlaceHolderBeanDefinitionVisitor(ff4j);
        // 2) Inject property & features value
        String[] beanNames = beanFactory.getBeanDefinitionNames();
        for (int i = 0; i < beanNames.length; i++) {
            if (beanNames[i].equals(beanName)) {
                continue;
            }
            BeanDefinition bd = beanFactory.getBeanDefinition(beanNames[i]);
            try {
                visitor.visitBeanDefinition(bd);
            } catch (BeanDefinitionStoreException ex) {
                throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanNames[i], ex.getMessage());
            }
        }
    } catch (Exception e) {
        LOGGER.error("Cannot handle placeholding through ff4j : ", e);
        throw new BeanInitializationException("An error occured during substition", e);
    }
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) BeanDefinitionVisitor(org.springframework.beans.factory.config.BeanDefinitionVisitor) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) BeansException(org.springframework.beans.BeansException) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException)

Example 49 with BeanDefinitionStoreException

use of org.springframework.beans.factory.BeanDefinitionStoreException in project geronimo-xbean by apache.

the class XBeanQNameHelper method getBeanInfo.

public BeanInfo getBeanInfo(String className) throws BeanDefinitionStoreException {
    if (className == null) {
        return null;
    }
    BeanInfo info = null;
    Class type = null;
    try {
        type = loadClass(className);
    } catch (ClassNotFoundException e) {
        throw new BeanDefinitionStoreException("Failed to load type: " + className + ". Reason: " + e, e);
    }
    try {
        info = Introspector.getBeanInfo(type);
    } catch (IntrospectionException e) {
        throw new BeanDefinitionStoreException("Failed to introspect type: " + className + ". Reason: " + e, e);
    }
    return info;
}
Also used : BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException)

Example 50 with BeanDefinitionStoreException

use of org.springframework.beans.factory.BeanDefinitionStoreException in project commons by terran4j.

the class Api2DocCollector method toApiParams.

public List<ApiParamObject> toApiParams(Method method, Class<?> defaultSeeClass) {
    List<ApiParamObject> result = new ArrayList<>();
    Set<String> paramIds = new HashSet<>();
    Parameter[] params = method.getParameters();
    if (params != null && params.length > 0) {
        String[] paramNames = parameterNameDiscoverer.getParameterNames(method);
        for (int i = 0; i < params.length; i++) {
            Parameter param = params[i];
            Class<?> paramClass = param.getType();
            ApiComment paramClassComment = paramClass.getAnnotation(ApiComment.class);
            if (paramClassComment != null) {
                // 从参数的类的属性中获取注释信息。
                List<ApiParamObject> paramsFromClass = toApiParams(paramClass, defaultSeeClass);
                for (ApiParamObject paramFromClass : paramsFromClass) {
                    if (paramIds.contains(paramFromClass.getId())) {
                        continue;
                    }
                    paramIds.add(paramFromClass.getId());
                    result.add(paramFromClass);
                }
            } else {
                // 从参数本身中获取注释信息。
                String paramName;
                if (paramNames != null) {
                    paramName = paramNames[i];
                } else {
                    paramName = param.getName();
                }
                ApiParamObject apiParamObject = toApiParam(param, paramName, param.getType(), defaultSeeClass);
                if (apiParamObject == null) {
                    continue;
                }
                String paramId = apiParamObject.getId();
                if (paramIds.contains(paramId)) {
                    String msg = "参数id值重复: " + paramId + ",所在方法: " + method;
                    throw new BeanDefinitionStoreException(msg);
                }
                paramIds.add(paramId);
                result.add(apiParamObject);
            }
        }
    }
    return result;
}
Also used : BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) ApiComment(com.terran4j.commons.api2doc.annotations.ApiComment) Parameter(java.lang.reflect.Parameter)

Aggregations

BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)59 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)18 Test (org.junit.Test)12 IOException (java.io.IOException)11 LinkedHashSet (java.util.LinkedHashSet)7 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)6 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)6 HashSet (java.util.HashSet)5 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)5 BeanDefinitionVisitor (org.springframework.beans.factory.config.BeanDefinitionVisitor)5 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)5 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)5 MockServletContext (org.springframework.mock.web.test.MockServletContext)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)4 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)4 Resource (org.springframework.core.io.Resource)4 Method (java.lang.reflect.Method)3 LinkedHashMap (java.util.LinkedHashMap)3