use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project leopard by tanhaichao.
the class LeopardBeanFactoryAware method registerBean.
// @PreDestroy
// public void destroy() {
// beanFactory = null;
// }
/**
* @desc 向spring容器注册bean
*
* @param beanName
*
* @param beanDefinition
*/
private static void registerBean(String beanName, BeanDefinition beanDefinition) {
BeanDefinitionRegistry beanDefinitonRegistry = (BeanDefinitionRegistry) beanFactory;
beanDefinitonRegistry.registerBeanDefinition(beanName, beanDefinition);
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-cloud-config by spring-cloud.
the class CompositeEnvironmentBeanFactoryPostProcessor method postProcessBeanFactory.
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
List<String> typePropertyList = CompositeUtils.getCompositeTypeList(environment);
for (int i = 0; i < typePropertyList.size(); i++) {
String type = typePropertyList.get(i);
String factoryName = CompositeUtils.getFactoryName(type, beanFactory);
Type[] factoryTypes = CompositeUtils.getEnvironmentRepositoryFactoryTypeParams(beanFactory, factoryName);
Class<? extends EnvironmentRepositoryProperties> propertiesClass = (Class<? extends EnvironmentRepositoryProperties>) factoryTypes[1];
EnvironmentRepositoryProperties properties = bindProperties(i, propertiesClass, environment);
AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(EnvironmentRepository.class).setFactoryMethodOnBean("build", factoryName).addConstructorArgValue(properties).getBeanDefinition();
String beanName = String.format("%s-env-repo%d", type, i);
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
registry.registerBeanDefinition(beanName, beanDefinition);
}
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project com.revolsys.open by revolsys.
the class ModuleImport method postProcessBeanFactory.
@Override
public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException {
if (beanFactory instanceof BeanDefinitionRegistry) {
final BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
postProcessBeanDefinitionRegistry(registry);
}
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-integration by spring-projects.
the class MicrometerMetricsTests method testSend.
@Test
public void testSend() {
GenericMessage<String> message = new GenericMessage<>("foo");
this.channel.send(message);
try {
this.channel.send(this.source.receive());
fail("Expected exception");
} catch (MessagingException e) {
assertThat(e.getCause().getMessage()).isEqualTo("testErrorCount");
}
this.channel2.send(message);
this.queue.send(message);
this.queue.send(message);
this.queue.receive();
this.badPoll.send(message);
try {
this.badPoll.receive();
fail("Expected exception");
} catch (RuntimeException e) {
assertThat(e.getMessage()).isEqualTo("badPoll");
}
nullChannel.send(message);
MeterRegistry registry = this.meterRegistry;
assertThat(registry.get("spring.integration.channels").gauge().value()).isEqualTo(6);
assertThat(registry.get("spring.integration.handlers").gauge().value()).isEqualTo(3);
assertThat(registry.get("spring.integration.sources").gauge().value()).isEqualTo(1);
assertThat(registry.get("spring.integration.receive").tag("name", "source").tag("result", "success").counter().count()).isEqualTo(1);
assertThat(registry.get("spring.integration.receive").tag("name", "badPoll").tag("result", "failure").counter().count()).isEqualTo(1);
assertThat(registry.get("spring.integration.send").tag("name", "eipBean.handler").tag("result", "success").timer().count()).isEqualTo(1);
assertThat(registry.get("spring.integration.send").tag("name", "eipMethod.handler").tag("result", "success").timer().count()).isEqualTo(1);
assertThat(registry.get("spring.integration.send").tag("name", "channel").tag("result", "success").timer().count()).isEqualTo(1);
assertThat(registry.get("spring.integration.send").tag("name", "channel").tag("result", "failure").timer().count()).isEqualTo(1);
assertThat(registry.get("spring.integration.send").tag("name", "eipMethod.handler").tag("result", "failure").timer().count()).isEqualTo(1);
assertThat(registry.get("spring.integration.receive").tag("name", "queue").tag("result", "success").counter().count()).isEqualTo(1);
assertThat(registry.get("spring.integration.send").tag("name", "nullChannel").tag("result", "success").timer().count()).isEqualTo(1);
BeanDefinitionRegistry beanFactory = (BeanDefinitionRegistry) this.context.getBeanFactory();
beanFactory.registerBeanDefinition("newChannel", BeanDefinitionBuilder.genericBeanDefinition(DirectChannel.class).getRawBeanDefinition());
DirectChannel newChannel = this.context.getBean("newChannel", DirectChannel.class);
newChannel.setBeanName("newChannel");
newChannel.subscribe(m -> {
});
newChannel.send(new GenericMessage<>("foo"));
assertThat(registry.get("spring.integration.send").tag("name", "newChannel").tag("result", "success").timer().count()).isEqualTo(1);
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-integration by spring-projects.
the class IntegrationNamespaceUtils method checkAndConfigureFixedSubscriberChannel.
@SuppressWarnings("unchecked")
public static void checkAndConfigureFixedSubscriberChannel(Element element, ParserContext parserContext, String channelName, String handlerBeanName) {
BeanDefinitionRegistry registry = parserContext.getRegistry();
if (registry.containsBeanDefinition(channelName)) {
BeanDefinition inputChannelDefinition = registry.getBeanDefinition(channelName);
if (FixedSubscriberChannel.class.getName().equals(inputChannelDefinition.getBeanClassName())) {
ConstructorArgumentValues constructorArgumentValues = inputChannelDefinition.getConstructorArgumentValues();
if (constructorArgumentValues.isEmpty()) {
constructorArgumentValues.addGenericArgumentValue(new RuntimeBeanReference(handlerBeanName));
} else {
parserContext.getReaderContext().error("Only one subscriber is allowed for a FixedSubscriberChannel.", element);
}
}
} else {
BeanDefinition bfppd;
if (!registry.containsBeanDefinition(IntegrationContextUtils.INTEGRATION_FIXED_SUBSCRIBER_CHANNEL_BPP_BEAN_NAME)) {
bfppd = new RootBeanDefinition(FixedSubscriberChannelBeanFactoryPostProcessor.class);
registry.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_FIXED_SUBSCRIBER_CHANNEL_BPP_BEAN_NAME, bfppd);
} else {
bfppd = registry.getBeanDefinition(IntegrationContextUtils.INTEGRATION_FIXED_SUBSCRIBER_CHANNEL_BPP_BEAN_NAME);
}
ManagedMap<String, String> candidates;
ValueHolder argumentValue = bfppd.getConstructorArgumentValues().getArgumentValue(0, Map.class);
if (argumentValue == null) {
candidates = new ManagedMap<String, String>();
bfppd.getConstructorArgumentValues().addIndexedArgumentValue(0, candidates);
} else {
candidates = (ManagedMap<String, String>) argumentValue.getValue();
}
candidates.put(handlerBeanName, channelName);
}
}
Aggregations