use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-framework by spring-projects.
the class Foo method setUp.
@BeforeEach
public void setUp() {
beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader((BeanDefinitionRegistry) beanFactory).loadBeanDefinitions(new ClassPathResource("FactoryBeanLookupTests-context.xml", this.getClass()));
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-framework by spring-projects.
the class AnnotationBeanNameGeneratorTests method generateBeanNameWithNamedComponentWhereTheNameIsBlank.
@Test
public void generateBeanNameWithNamedComponentWhereTheNameIsBlank() {
BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentWithBlankName.class);
String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
assertThat(beanName).as("The generated beanName must *never* be null.").isNotNull();
assertThat(StringUtils.hasText(beanName)).as("The generated beanName must *never* be blank.").isTrue();
String expectedGeneratedBeanName = this.beanNameGenerator.buildDefaultBeanName(bd);
assertThat(beanName).isEqualTo(expectedGeneratedBeanName);
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-framework by spring-projects.
the class AnnotationBeanNameGeneratorTests method generateBeanNameFromComposedControllerAnnotationWithStringValue.
@Test
public void generateBeanNameFromComposedControllerAnnotationWithStringValue() {
// SPR-11360
BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComposedControllerAnnotationWithStringValue.class);
String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
assertThat(beanName).isEqualTo("restController");
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-framework by spring-projects.
the class AnnotationConfigWebApplicationContextTests method withBeanNameGenerator.
@Test
@SuppressWarnings("resource")
public void withBeanNameGenerator() {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.setBeanNameGenerator(new AnnotationBeanNameGenerator() {
@Override
public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
return "custom-" + super.generateBeanName(definition, registry);
}
});
ctx.setConfigLocation(Config.class.getName());
ctx.refresh();
assertThat(ctx.containsBean("custom-myConfig")).isTrue();
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-framework by spring-projects.
the class AnnotationDrivenJmsBeanDefinitionParser method parse.
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
Object source = parserContext.extractSource(element);
// Register component for the surrounding <jms:annotation-driven> element.
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
parserContext.pushContainingComponent(compDefinition);
// Nest the concrete post-processor bean in the surrounding component.
BeanDefinitionRegistry registry = parserContext.getRegistry();
if (registry.containsBeanDefinition(JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)) {
parserContext.getReaderContext().error("Only one JmsListenerAnnotationBeanPostProcessor may exist within the context.", source);
} else {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition("org.springframework.jms.annotation.JmsListenerAnnotationBeanPostProcessor");
builder.getRawBeanDefinition().setSource(source);
String endpointRegistry = element.getAttribute("registry");
if (StringUtils.hasText(endpointRegistry)) {
builder.addPropertyReference("endpointRegistry", endpointRegistry);
} else {
registerDefaultEndpointRegistry(source, parserContext);
}
String containerFactory = element.getAttribute("container-factory");
if (StringUtils.hasText(containerFactory)) {
builder.addPropertyValue("containerFactoryBeanName", containerFactory);
}
String handlerMethodFactory = element.getAttribute("handler-method-factory");
if (StringUtils.hasText(handlerMethodFactory)) {
builder.addPropertyReference("messageHandlerMethodFactory", handlerMethodFactory);
}
registerInfrastructureBean(parserContext, builder, JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME);
}
// Finally register the composite component.
parserContext.popAndRegisterContainingComponent();
return null;
}
Aggregations