use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.
the class JcaListenerContainerParser method parseSpecificContainerProperties.
@Override
protected MutablePropertyValues parseSpecificContainerProperties(Element containerEle, ParserContext parserContext) {
MutablePropertyValues properties = new MutablePropertyValues();
if (containerEle.hasAttribute(RESOURCE_ADAPTER_ATTRIBUTE)) {
String resourceAdapterBeanName = containerEle.getAttribute(RESOURCE_ADAPTER_ATTRIBUTE);
if (!StringUtils.hasText(resourceAdapterBeanName)) {
parserContext.getReaderContext().error("Listener container 'resource-adapter' attribute contains empty value.", containerEle);
} else {
properties.add("resourceAdapter", new RuntimeBeanReference(resourceAdapterBeanName));
}
}
String activationSpecFactoryBeanName = containerEle.getAttribute(ACTIVATION_SPEC_FACTORY_ATTRIBUTE);
String destinationResolverBeanName = containerEle.getAttribute(DESTINATION_RESOLVER_ATTRIBUTE);
if (StringUtils.hasText(activationSpecFactoryBeanName)) {
if (StringUtils.hasText(destinationResolverBeanName)) {
parserContext.getReaderContext().error("Specify either 'activation-spec-factory' or " + "'destination-resolver', not both. If you define a dedicated JmsActivationSpecFactory bean, " + "specify the custom DestinationResolver there (if possible).", containerEle);
}
properties.add("activationSpecFactory", new RuntimeBeanReference(activationSpecFactoryBeanName));
}
if (StringUtils.hasText(destinationResolverBeanName)) {
properties.add("destinationResolver", new RuntimeBeanReference(destinationResolverBeanName));
}
String transactionManagerBeanName = containerEle.getAttribute(TRANSACTION_MANAGER_ATTRIBUTE);
if (StringUtils.hasText(transactionManagerBeanName)) {
properties.add("transactionManager", new RuntimeBeanReference(transactionManagerBeanName));
}
String phase = containerEle.getAttribute(PHASE_ATTRIBUTE);
if (StringUtils.hasText(phase)) {
properties.add("phase", phase);
}
return properties;
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.
the class JmsListenerContainerParser method parseSpecificContainerProperties.
@Override
protected MutablePropertyValues parseSpecificContainerProperties(Element containerEle, ParserContext parserContext) {
MutablePropertyValues properties = new MutablePropertyValues();
boolean isSimpleContainer = containerEle.getAttribute(CONTAINER_TYPE_ATTRIBUTE).startsWith("simple");
String connectionFactoryBeanName = "connectionFactory";
if (containerEle.hasAttribute(CONNECTION_FACTORY_ATTRIBUTE)) {
connectionFactoryBeanName = containerEle.getAttribute(CONNECTION_FACTORY_ATTRIBUTE);
if (!StringUtils.hasText(connectionFactoryBeanName)) {
parserContext.getReaderContext().error("Listener container 'connection-factory' attribute contains empty value.", containerEle);
}
}
if (StringUtils.hasText(connectionFactoryBeanName)) {
properties.add("connectionFactory", new RuntimeBeanReference(connectionFactoryBeanName));
}
String taskExecutorBeanName = containerEle.getAttribute(TASK_EXECUTOR_ATTRIBUTE);
if (StringUtils.hasText(taskExecutorBeanName)) {
properties.add("taskExecutor", new RuntimeBeanReference(taskExecutorBeanName));
}
String errorHandlerBeanName = containerEle.getAttribute(ERROR_HANDLER_ATTRIBUTE);
if (StringUtils.hasText(errorHandlerBeanName)) {
properties.add("errorHandler", new RuntimeBeanReference(errorHandlerBeanName));
}
String destinationResolverBeanName = containerEle.getAttribute(DESTINATION_RESOLVER_ATTRIBUTE);
if (StringUtils.hasText(destinationResolverBeanName)) {
properties.add("destinationResolver", new RuntimeBeanReference(destinationResolverBeanName));
}
String cache = containerEle.getAttribute(CACHE_ATTRIBUTE);
if (StringUtils.hasText(cache)) {
if (isSimpleContainer) {
if (!("auto".equals(cache) || "consumer".equals(cache))) {
parserContext.getReaderContext().warning("'cache' attribute not actively supported for listener container of type \"simple\". " + "Effective runtime behavior will be equivalent to \"consumer\" / \"auto\".", containerEle);
}
} else {
properties.add("cacheLevelName", "CACHE_" + cache.toUpperCase());
}
}
Integer acknowledgeMode = parseAcknowledgeMode(containerEle, parserContext);
if (acknowledgeMode != null) {
if (acknowledgeMode == Session.SESSION_TRANSACTED) {
properties.add("sessionTransacted", Boolean.TRUE);
} else {
properties.add("sessionAcknowledgeMode", acknowledgeMode);
}
}
String transactionManagerBeanName = containerEle.getAttribute(TRANSACTION_MANAGER_ATTRIBUTE);
if (StringUtils.hasText(transactionManagerBeanName)) {
if (isSimpleContainer) {
parserContext.getReaderContext().error("'transaction-manager' attribute not supported for listener container of type \"simple\".", containerEle);
} else {
properties.add("transactionManager", new RuntimeBeanReference(transactionManagerBeanName));
}
}
String concurrency = containerEle.getAttribute(CONCURRENCY_ATTRIBUTE);
if (StringUtils.hasText(concurrency)) {
properties.add("concurrency", concurrency);
}
String prefetch = containerEle.getAttribute(PREFETCH_ATTRIBUTE);
if (StringUtils.hasText(prefetch)) {
if (!isSimpleContainer) {
properties.add("maxMessagesPerTask", prefetch);
}
}
String phase = containerEle.getAttribute(PHASE_ATTRIBUTE);
if (StringUtils.hasText(phase)) {
properties.add("phase", phase);
}
String receiveTimeout = containerEle.getAttribute(RECEIVE_TIMEOUT_ATTRIBUTE);
if (StringUtils.hasText(receiveTimeout)) {
if (!isSimpleContainer) {
properties.add("receiveTimeout", receiveTimeout);
}
}
String backOffBeanName = containerEle.getAttribute(BACK_OFF_ATTRIBUTE);
if (StringUtils.hasText(backOffBeanName)) {
if (!isSimpleContainer) {
properties.add("backOff", new RuntimeBeanReference(backOffBeanName));
}
} else {
// No need to consider this if back-off is set
String recoveryInterval = containerEle.getAttribute(RECOVERY_INTERVAL_ATTRIBUTE);
if (StringUtils.hasText(recoveryInterval)) {
if (!isSimpleContainer) {
properties.add("recoveryInterval", recoveryInterval);
}
}
}
return properties;
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.
the class ApplicationContextEventTests method listenersInApplicationContext.
@Test
public void listenersInApplicationContext() {
StaticApplicationContext context = new StaticApplicationContext();
context.registerBeanDefinition("listener1", new RootBeanDefinition(MyOrderedListener1.class));
RootBeanDefinition listener2 = new RootBeanDefinition(MyOrderedListener2.class);
listener2.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference("listener1"));
listener2.setLazyInit(true);
context.registerBeanDefinition("listener2", listener2);
context.refresh();
assertFalse(context.getDefaultListableBeanFactory().containsSingleton("listener2"));
MyOrderedListener1 listener1 = context.getBean("listener1", MyOrderedListener1.class);
MyOtherEvent event1 = new MyOtherEvent(context);
context.publishEvent(event1);
assertFalse(context.getDefaultListableBeanFactory().containsSingleton("listener2"));
MyEvent event2 = new MyEvent(context);
context.publishEvent(event2);
assertTrue(context.getDefaultListableBeanFactory().containsSingleton("listener2"));
MyEvent event3 = new MyEvent(context);
context.publishEvent(event3);
MyOtherEvent event4 = new MyOtherEvent(context);
context.publishEvent(event4);
assertTrue(listener1.seenEvents.contains(event1));
assertTrue(listener1.seenEvents.contains(event2));
assertTrue(listener1.seenEvents.contains(event3));
assertTrue(listener1.seenEvents.contains(event4));
listener1.seenEvents.clear();
context.publishEvent(event1);
context.publishEvent(event2);
context.publishEvent(event3);
context.publishEvent(event4);
assertTrue(listener1.seenEvents.contains(event1));
assertTrue(listener1.seenEvents.contains(event2));
assertTrue(listener1.seenEvents.contains(event3));
assertTrue(listener1.seenEvents.contains(event4));
AbstractApplicationEventMulticaster multicaster = context.getBean(AbstractApplicationEventMulticaster.class);
assertEquals(2, multicaster.retrieverCache.size());
context.close();
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.
the class PropertyResourceConfigurerIntegrationTests method testPropertyPlaceholderConfigurerWithSystemPropertyInLocation.
@Test
public void testPropertyPlaceholderConfigurerWithSystemPropertyInLocation() {
StaticApplicationContext ac = new StaticApplicationContext();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("spouse", new RuntimeBeanReference("${ref}"));
ac.registerSingleton("tb", TestBean.class, pvs);
pvs = new MutablePropertyValues();
pvs.add("location", "${user.dir}/test");
ac.registerSingleton("configurer", PropertyPlaceholderConfigurer.class, pvs);
try {
ac.refresh();
fail("Should have thrown BeanInitializationException");
} catch (BeanInitializationException ex) {
// expected
assertTrue(ex.getCause() instanceof FileNotFoundException);
// slight hack for Linux/Unix systems
String userDir = StringUtils.cleanPath(System.getProperty("user.dir"));
if (userDir.startsWith("/")) {
userDir = userDir.substring(1);
}
assertTrue(ex.getMessage().indexOf(userDir) != -1);
}
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.
the class JeeNamespaceHandlerTests method testWithEnvironment.
@Test
public void testWithEnvironment() throws Exception {
BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("withEnvironment");
assertPropertyValue(beanDefinition, "jndiEnvironment", "foo=bar");
assertPropertyValue(beanDefinition, "defaultObject", new RuntimeBeanReference("myBean"));
}
Aggregations