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.");
}
}
}
}
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;
}
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);
}
}
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;
}
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;
}
Aggregations