use of org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition in project spring-framework by spring-projects.
the class AnnotationScopeMetadataResolverTests method customRequestScopeWithAttribute.
@Test
public void customRequestScopeWithAttribute() {
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithCustomRequestScopeWithAttributeOverride.class);
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
assertEquals("request", scopeMetadata.getScopeName());
assertEquals(TARGET_CLASS, scopeMetadata.getScopedProxyMode());
}
use of org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition in project spring-framework by spring-projects.
the class AnnotationScopeMetadataResolverTests method resolveScopeMetadataShouldApplyScopedProxyModeToPrototype.
@Test
public void resolveScopeMetadataShouldApplyScopedProxyModeToPrototype() {
this.scopeMetadataResolver = new AnnotationScopeMetadataResolver(INTERFACES);
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithPrototypeScope.class);
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
assertEquals(BeanDefinition.SCOPE_PROTOTYPE, scopeMetadata.getScopeName());
assertEquals(INTERFACES, scopeMetadata.getScopedProxyMode());
}
use of org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition in project spring-framework by spring-projects.
the class AnnotatedBeanDefinitionReader method doRegisterBean.
/**
* Register a bean from the given bean class, deriving its metadata from
* class-declared annotations.
* @param annotatedClass the class of the bean
* @param instanceSupplier a callback for creating an instance of the bean
* (may be {@code null})
* @param name an explicit name for the bean
* @param qualifiers specific qualifier annotations to consider, if any,
* in addition to qualifiers at the bean class level
* @param definitionCustomizers one or more callbacks for customizing the
* factory's {@link BeanDefinition}, e.g. setting a lazy-init or primary flag
* @since 5.0
*/
<T> void doRegisterBean(Class<T> annotatedClass, Supplier<T> instanceSupplier, String name, Class<? extends Annotation>[] qualifiers, BeanDefinitionCustomizer... definitionCustomizers) {
AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);
if (this.conditionEvaluator.shouldSkip(abd.getMetadata())) {
return;
}
abd.setInstanceSupplier(instanceSupplier);
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(abd);
abd.setScope(scopeMetadata.getScopeName());
String beanName = (name != null ? name : this.beanNameGenerator.generateBeanName(abd, this.registry));
AnnotationConfigUtils.processCommonDefinitionAnnotations(abd);
if (qualifiers != null) {
for (Class<? extends Annotation> qualifier : qualifiers) {
if (Primary.class == qualifier) {
abd.setPrimary(true);
} else if (Lazy.class == qualifier) {
abd.setLazyInit(true);
} else {
abd.addQualifier(new AutowireCandidateQualifier(qualifier));
}
}
}
if (definitionCustomizers != null) {
for (BeanDefinitionCustomizer customizer : definitionCustomizers) {
customizer.customize(abd);
}
}
BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(abd, beanName);
definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, this.registry);
}
use of org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition 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);
assertNotNull("The generated beanName must *never* be null.", beanName);
assertTrue("The generated beanName must *never* be blank.", StringUtils.hasText(beanName));
String expectedGeneratedBeanName = this.beanNameGenerator.buildDefaultBeanName(bd);
assertEquals(expectedGeneratedBeanName, beanName);
}
use of org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition in project spring-framework by spring-projects.
the class AnnotationBeanNameGeneratorTests method generateBeanNameFromComposedControllerAnnotationWithStringValue.
/**
* @since 4.0.1
* @see https://jira.spring.io/browse/SPR-11360
*/
@Test
public void generateBeanNameFromComposedControllerAnnotationWithStringValue() {
BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComposedControllerAnnotationWithStringValue.class);
String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
assertEquals("restController", beanName);
}
Aggregations