use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project cuba by cuba-platform.
the class PortalRemoteProxyBeanCreator method postProcessBeanFactory.
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
String useLocal = AppContext.getProperty("cuba.useLocalServiceInvocation");
if (Boolean.valueOf(useLocal)) {
log.info("Configuring proxy beans for local service invocations: " + services.keySet());
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
for (Map.Entry<String, String> entry : services.entrySet()) {
String name = entry.getKey();
String serviceInterface = entry.getValue();
BeanDefinition definition = new RootBeanDefinition(LocalServiceProxy.class);
MutablePropertyValues propertyValues = definition.getPropertyValues();
propertyValues.add("serviceName", name);
propertyValues.add("serviceInterface", serviceInterface);
registry.registerBeanDefinition(name, definition);
log.debug("Configured proxy bean " + name + " of type " + serviceInterface);
}
processSubstitutions(beanFactory);
} else {
super.postProcessBeanFactory(beanFactory);
}
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project cuba by cuba-platform.
the class RemoteProxyBeanCreator method postProcessBeanFactory.
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
log.info("Configuring remote proxy beans: " + services.keySet());
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
for (Map.Entry<String, String> entry : services.entrySet()) {
String name = entry.getKey();
String serviceUrl = name;
String serviceInterface = entry.getValue();
BeanDefinition definition = new RootBeanDefinition(HttpServiceProxy.class);
definition.getConstructorArgumentValues().addIndexedArgumentValue(0, serverSelector);
MutablePropertyValues propertyValues = definition.getPropertyValues();
propertyValues.add("serviceUrl", serviceUrl);
propertyValues.add("serviceInterface", serviceInterface);
registry.registerBeanDefinition(name, definition);
log.debug("Configured remote proxy bean " + name + " of type " + serviceInterface + ", bound to " + serviceUrl);
}
processSubstitutions(beanFactory);
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project dubbo by alibaba.
the class AnnotationBean method postProcessBeanFactory.
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
if (annotationPackage == null || annotationPackage.length() == 0) {
return;
}
if (beanFactory instanceof BeanDefinitionRegistry) {
try {
// init scanner
Class<?> scannerClass = ReflectUtils.forName("org.springframework.context.annotation.ClassPathBeanDefinitionScanner");
Object scanner = scannerClass.getConstructor(new Class<?>[] { BeanDefinitionRegistry.class, boolean.class }).newInstance(new Object[] { (BeanDefinitionRegistry) beanFactory, true });
// add filter
Class<?> filterClass = ReflectUtils.forName("org.springframework.core.type.filter.AnnotationTypeFilter");
Object filter = filterClass.getConstructor(Class.class).newInstance(Service.class);
Method addIncludeFilter = scannerClass.getMethod("addIncludeFilter", ReflectUtils.forName("org.springframework.core.type.filter.TypeFilter"));
addIncludeFilter.invoke(scanner, filter);
// scan packages
String[] packages = Constants.COMMA_SPLIT_PATTERN.split(annotationPackage);
Method scan = scannerClass.getMethod("scan", new Class<?>[] { String[].class });
scan.invoke(scanner, new Object[] { packages });
} catch (Throwable e) {
// spring 2.0
}
}
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterParser method parse.
/* (non-Javadoc)
* @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
*/
public BeanDefinition parse(Element element, ParserContext parserContext) {
if (parserContext.isNested()) {
parserContext.getReaderContext().error("Mongo Converter must not be defined as nested bean.", element);
}
BeanDefinitionRegistry registry = parserContext.getRegistry();
String id = element.getAttribute(AbstractBeanDefinitionParser.ID_ATTRIBUTE);
id = StringUtils.hasText(id) ? id : DEFAULT_CONVERTER_BEAN_NAME;
parserContext.pushContainingComponent(new CompositeComponentDefinition("Mapping Mongo Converter", element));
BeanDefinition conversionsDefinition = getCustomConversions(element, parserContext);
String ctxRef = potentiallyCreateMappingContext(element, parserContext, conversionsDefinition, id);
createIsNewStrategyFactoryBeanDefinition(ctxRef, parserContext, element);
// Need a reference to a Mongo instance
String dbFactoryRef = element.getAttribute("db-factory-ref");
if (!StringUtils.hasText(dbFactoryRef)) {
dbFactoryRef = DB_FACTORY_BEAN_NAME;
}
// Converter
BeanDefinitionBuilder converterBuilder = BeanDefinitionBuilder.genericBeanDefinition(MappingMongoConverter.class);
converterBuilder.addConstructorArgReference(dbFactoryRef);
converterBuilder.addConstructorArgReference(ctxRef);
String typeMapperRef = element.getAttribute("type-mapper-ref");
if (StringUtils.hasText(typeMapperRef)) {
converterBuilder.addPropertyReference("typeMapper", typeMapperRef);
}
if (conversionsDefinition != null) {
converterBuilder.addPropertyValue("customConversions", conversionsDefinition);
}
if (!registry.containsBeanDefinition("indexOperationsProvider")) {
BeanDefinitionBuilder indexOperationsProviderBuilder = BeanDefinitionBuilder.genericBeanDefinition("org.springframework.data.mongodb.core.DefaultIndexOperationsProvider");
indexOperationsProviderBuilder.addConstructorArgReference(dbFactoryRef);
indexOperationsProviderBuilder.addConstructorArgValue(BeanDefinitionBuilder.genericBeanDefinition(QueryMapper.class).addConstructorArgReference(id).getBeanDefinition());
parserContext.registerBeanComponent(new BeanComponentDefinition(indexOperationsProviderBuilder.getBeanDefinition(), "indexOperationsProvider"));
}
try {
registry.getBeanDefinition(INDEX_HELPER_BEAN_NAME);
} catch (NoSuchBeanDefinitionException ignored) {
BeanDefinitionBuilder indexHelperBuilder = BeanDefinitionBuilder.genericBeanDefinition(MongoPersistentEntityIndexCreator.class);
indexHelperBuilder.addConstructorArgReference(ctxRef);
indexHelperBuilder.addConstructorArgReference("indexOperationsProvider");
indexHelperBuilder.addDependsOn(ctxRef);
parserContext.registerBeanComponent(new BeanComponentDefinition(indexHelperBuilder.getBeanDefinition(), INDEX_HELPER_BEAN_NAME));
}
BeanDefinition validatingMongoEventListener = potentiallyCreateValidatingMongoEventListener(element, parserContext);
if (validatingMongoEventListener != null) {
parserContext.registerBeanComponent(new BeanComponentDefinition(validatingMongoEventListener, VALIDATING_EVENT_LISTENER_BEAN_NAME));
}
parserContext.registerBeanComponent(new BeanComponentDefinition(converterBuilder.getBeanDefinition(), id));
parserContext.popAndRegisterContainingComponent();
return null;
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterParserIntegrationTests method rejectsInvalidFieldNamingStrategyConfiguration.
// DATAMONGO-866
@Test
public void rejectsInvalidFieldNamingStrategyConfiguration() {
exception.expect(BeanDefinitionParsingException.class);
exception.expectMessage("abbreviation");
exception.expectMessage("field-naming-strategy-ref");
BeanDefinitionRegistry factory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
reader.loadBeanDefinitions(new ClassPathResource("namespace/converter-invalid.xml"));
}
Aggregations