List of usage examples for org.springframework.beans.factory BeanDefinitionStoreException BeanDefinitionStoreException
public BeanDefinitionStoreException(String msg)
From source file:org.springframework.integration.comet.core.transport.AbstractCometMessagingTransport.java
/** * Implemented after properties set method from {@link InitializingBean} */// ww w .j a v a2s .co m public final void initializeTransport() throws Exception { if (defaultMessageSerializer == null) throw new BeanDefinitionStoreException("A default serializer is mandatory to send messaged to " + "comet endpoint, found a null serializer"); if (!StringUtils.hasText(messageParamName)) throw new BeanDefinitionStoreException("A non null non empty message parameter name is required"); if (executor == null) throw new BeanDefinitionStoreException("A non null executor service is required"); if (defaultMessageSerializer instanceof CometMessageJSONSerializer) ((CometMessageJSONSerializer) defaultMessageSerializer).setCommonPrefix(messageParamName); init(); }
From source file:org.springframework.integration.config.IdGeneratorConfigurer.java
private boolean setIdGenerator(ApplicationContext context) { try {//from w w w . j a va 2s . c o m IdGenerator idGeneratorBean = context.getBean(IdGenerator.class); if (logger.isDebugEnabled()) { logger.debug("using custom MessageHeaders.IdGenerator [" + idGeneratorBean.getClass() + "]"); } Field idGeneratorField = ReflectionUtils.findField(MessageHeaders.class, "idGenerator"); ReflectionUtils.makeAccessible(idGeneratorField); IdGenerator currentIdGenerator = (IdGenerator) ReflectionUtils.getField(idGeneratorField, null); if (currentIdGenerator != null) { if (currentIdGenerator.equals(idGeneratorBean)) { // same instance is already set, nothing needs to be done return false; } else { if (IdGeneratorConfigurer.theIdGenerator.getClass() == idGeneratorBean.getClass()) { if (logger.isWarnEnabled()) { logger.warn("Another instance of " + idGeneratorBean.getClass() + " has already been established; ignoring"); } return true; } else { // different instance has been set, not legal throw new BeanDefinitionStoreException( "'MessageHeaders.idGenerator' has already been set and can not be set again"); } } } if (logger.isInfoEnabled()) { logger.info("Message IDs will be generated using custom IdGenerator [" + idGeneratorBean.getClass() + "]"); } ReflectionUtils.setField(idGeneratorField, null, idGeneratorBean); IdGeneratorConfigurer.theIdGenerator = idGeneratorBean; } catch (NoSuchBeanDefinitionException e) { // No custom IdGenerator. We will use the default. int idBeans = context.getBeansOfType(IdGenerator.class).size(); if (idBeans > 1 && logger.isWarnEnabled()) { logger.warn("Found too many 'IdGenerator' beans (" + idBeans + ") " + "Will use the existing UUID strategy."); } else if (logger.isDebugEnabled()) { logger.debug("Unable to locate MessageHeaders.IdGenerator. Will use the existing UUID strategy."); } return false; } catch (IllegalStateException e) { // thrown from ReflectionUtils if (logger.isWarnEnabled()) { logger.warn("Unexpected exception occurred while accessing idGenerator of MessageHeaders." + " Will use the existing UUID strategy.", e); } return false; } return true; }
From source file:org.springframework.integration.config.MessagingGatewayRegistrar.java
public BeanDefinitionHolder parse(Map<String, Object> gatewayAttributes) { String defaultPayloadExpression = (String) gatewayAttributes.get("defaultPayloadExpression"); @SuppressWarnings("unchecked") Map<String, Object>[] defaultHeaders = (Map<String, Object>[]) gatewayAttributes.get("defaultHeaders"); String defaultRequestChannel = (String) gatewayAttributes.get("defaultRequestChannel"); String defaultReplyChannel = (String) gatewayAttributes.get("defaultReplyChannel"); String errorChannel = (String) gatewayAttributes.get("errorChannel"); String asyncExecutor = (String) gatewayAttributes.get("asyncExecutor"); String mapper = (String) gatewayAttributes.get("mapper"); boolean hasMapper = StringUtils.hasText(mapper); boolean hasDefaultPayloadExpression = StringUtils.hasText(defaultPayloadExpression); Assert.state(!hasMapper || !hasDefaultPayloadExpression, "'defaultPayloadExpression' is not allowed when a 'mapper' is provided"); boolean hasDefaultHeaders = !ObjectUtils.isEmpty(defaultHeaders); Assert.state(!hasMapper || !hasDefaultHeaders, "'defaultHeaders' are not allowed when a 'mapper' is provided"); BeanDefinitionBuilder gatewayProxyBuilder = BeanDefinitionBuilder .genericBeanDefinition(GatewayProxyFactoryBean.class); if (hasDefaultHeaders || hasDefaultPayloadExpression) { BeanDefinitionBuilder methodMetadataBuilder = BeanDefinitionBuilder .genericBeanDefinition(GatewayMethodMetadata.class); if (hasDefaultPayloadExpression) { methodMetadataBuilder.addPropertyValue("payloadExpression", defaultPayloadExpression); }//from ww w . j a v a 2 s. c o m Map<String, Object> headerExpressions = new ManagedMap<String, Object>(); for (Map<String, Object> header : defaultHeaders) { String headerValue = (String) header.get("value"); String headerExpression = (String) header.get("expression"); boolean hasValue = StringUtils.hasText(headerValue); if (!(hasValue ^ StringUtils.hasText(headerExpression))) { throw new BeanDefinitionStoreException( "exactly one of 'value' or 'expression' " + "is required on a gateway's header."); } BeanDefinition expressionDef = new RootBeanDefinition( hasValue ? LiteralExpression.class : ExpressionFactoryBean.class); expressionDef.getConstructorArgumentValues() .addGenericArgumentValue(hasValue ? headerValue : headerExpression); headerExpressions.put((String) header.get("name"), expressionDef); } methodMetadataBuilder.addPropertyValue("headerExpressions", headerExpressions); gatewayProxyBuilder.addPropertyValue("globalMethodMetadata", methodMetadataBuilder.getBeanDefinition()); } if (StringUtils.hasText(defaultRequestChannel)) { gatewayProxyBuilder.addPropertyReference("defaultRequestChannel", defaultRequestChannel); } if (StringUtils.hasText(defaultReplyChannel)) { gatewayProxyBuilder.addPropertyReference("defaultReplyChannel", defaultReplyChannel); } if (StringUtils.hasText(errorChannel)) { gatewayProxyBuilder.addPropertyReference("errorChannel", errorChannel); } if (StringUtils.hasText(asyncExecutor)) { gatewayProxyBuilder.addPropertyReference("asyncExecutor", asyncExecutor); } if (StringUtils.hasText(mapper)) { gatewayProxyBuilder.addPropertyReference("mapper", mapper); } gatewayProxyBuilder.addPropertyValue("defaultRequestTimeout", gatewayAttributes.get("defaultRequestTimeout")); gatewayProxyBuilder.addPropertyValue("defaultReplyTimeout", gatewayAttributes.get("defaultReplyTimeout")); gatewayProxyBuilder.addPropertyValue("methodMetadataMap", gatewayAttributes.get("methods")); String serviceInterface = (String) gatewayAttributes.get("serviceInterface"); if (!StringUtils.hasText(serviceInterface)) { serviceInterface = "org.springframework.integration.gateway.RequestReplyExchanger"; } String id = (String) gatewayAttributes.get("name"); if (!StringUtils.hasText(id)) { id = Introspector.decapitalize(serviceInterface.substring(serviceInterface.lastIndexOf(".") + 1)); } gatewayProxyBuilder.addConstructorArgValue(serviceInterface); return new BeanDefinitionHolder(gatewayProxyBuilder.getBeanDefinition(), id); }
From source file:org.springframework.integration.config.PublisherRegistrar.java
@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 + "'."); }// w ww.j av a 2 s . c o m } 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."); } } } }