org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition Java Examples

The following examples show how to use org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JsfCdiToSpringApplicationBeanFactoryPostProcessorIT.java    From joinfaces with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoScopedClass() {
	GenericApplicationContext acx = new GenericApplicationContext();
	AnnotationConfigUtils.registerAnnotationConfigProcessors(acx);

	acx.registerBeanDefinition("noScopedClass", new AnnotatedGenericBeanDefinition(
		new StandardAnnotationMetadata(NoScopedClass.class)));
	acx.registerBeanDefinition("scopedBeansConfiguration", new RootBeanDefinition(
		ScopedBeansConfiguration.class));
	acx.addBeanFactoryPostProcessor(JsfScopeAnnotationsAutoConfiguration.jsfScopeAnnotationsConfigurer(acx.getEnvironment()));
	acx.addBeanFactoryPostProcessor(CdiScopeAnnotationsAutoConfiguration.cdiScopeAnnotationsConfigurer(acx.getEnvironment()));
	acx.refresh();

	assertThat(acx.getBeanDefinition("noScopedClass").getScope())
		.isEqualTo("");
	assertThat(acx.getBeanDefinition("noScopedBean").getScope())
		.isEqualTo("");

}
 
Example #2
Source File: ConfigurationClassBeanDefinitionReader.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Register the {@link Configuration} class itself as a bean definition.
 */
private void registerBeanDefinitionForImportedConfigurationClass(ConfigurationClass configClass) {
	AnnotationMetadata metadata = configClass.getMetadata();
	AnnotatedGenericBeanDefinition configBeanDef = new AnnotatedGenericBeanDefinition(metadata);

	ScopeMetadata scopeMetadata = scopeMetadataResolver.resolveScopeMetadata(configBeanDef);
	configBeanDef.setScope(scopeMetadata.getScopeName());
	String configBeanName = this.importBeanNameGenerator.generateBeanName(configBeanDef, this.registry);
	AnnotationConfigUtils.processCommonDefinitionAnnotations(configBeanDef, metadata);

	BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(configBeanDef, configBeanName);
	definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
	this.registry.registerBeanDefinition(definitionHolder.getBeanName(), definitionHolder.getBeanDefinition());
	configClass.setBeanName(configBeanName);

	if (logger.isDebugEnabled()) {
		logger.debug("Registered bean definition for imported class '" + configBeanName + "'");
	}
}
 
Example #3
Source File: ConfigurationClassBeanDefinitionReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Register the {@link Configuration} class itself as a bean definition.
 */
private void registerBeanDefinitionForImportedConfigurationClass(ConfigurationClass configClass) {
	AnnotationMetadata metadata = configClass.getMetadata();
	AnnotatedGenericBeanDefinition configBeanDef = new AnnotatedGenericBeanDefinition(metadata);

	ScopeMetadata scopeMetadata = scopeMetadataResolver.resolveScopeMetadata(configBeanDef);
	configBeanDef.setScope(scopeMetadata.getScopeName());
	String configBeanName = this.importBeanNameGenerator.generateBeanName(configBeanDef, this.registry);
	AnnotationConfigUtils.processCommonDefinitionAnnotations(configBeanDef, metadata);

	BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(configBeanDef, configBeanName);
	definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
	this.registry.registerBeanDefinition(definitionHolder.getBeanName(), definitionHolder.getBeanDefinition());
	configClass.setBeanName(configBeanName);

	if (logger.isDebugEnabled()) {
		logger.debug("Registered bean definition for imported class '" + configBeanName + "'");
	}
}
 
Example #4
Source File: SpringBeanRegister.java    From springboot-plugin-framework-parent with Apache License 2.0 6 votes vote down vote up
/**
 * 默认注册
 * @param pluginId 插件id
 * @param suffixName bean 后缀名称
 * @param aClass 注册的类
 * @param consumer 自定义处理AnnotatedGenericBeanDefinition
 * @return 注册的bean名称
 */
public String register(String pluginId, String suffixName, Class<?> aClass,
                       Consumer<AnnotatedGenericBeanDefinition> consumer) {
    AnnotatedGenericBeanDefinition beanDefinition = new
            AnnotatedGenericBeanDefinition(aClass);

    BeanNameGenerator beanNameGenerator =
            new PluginAnnotationBeanNameGenerator(suffixName);
    String beanName = beanNameGenerator.generateBeanName(beanDefinition, applicationContext);
    if(PluginInfoContainer.existRegisterBeanName((beanName))){
        String error = MessageFormat.format("Bean name {0} already exist of {1}",
                beanName, aClass.getName());
        logger.error(error);
        return null;
    }
    if(consumer != null){
        consumer.accept(beanDefinition);
    }
    applicationContext.registerBeanDefinition(beanName, beanDefinition);
    PluginInfoContainer.addRegisterBeanName(pluginId, beanName);
    return beanName;
}
 
Example #5
Source File: SpringBeanRegister.java    From springboot-plugin-framework-parent with Apache License 2.0 6 votes vote down vote up
/**
 * 指定bean名称注册
 * @param pluginId 插件id
 * @param beanName 指定的bean名称
 * @param aClass 注册的类
 * @param consumer 注册异常
 */
public void registerOfSpecifyName(String pluginId,
                                  String beanName,
                                  Class<?> aClass,
                                  Consumer<AnnotatedGenericBeanDefinition> consumer) {
    AnnotatedGenericBeanDefinition beanDefinition = new
            AnnotatedGenericBeanDefinition(aClass);
    if(PluginInfoContainer.existRegisterBeanName((beanName))){
        String error = MessageFormat.format("Bean name {0} already exist of {1}",
                beanName, aClass.getName());
        throw new RuntimeException(error);
    }
    if(consumer != null){
        consumer.accept(beanDefinition);
    }
    PluginInfoContainer.addRegisterBeanName(pluginId, beanName);
    applicationContext.registerBeanDefinition(beanName, beanDefinition);
}
 
Example #6
Source File: ConfigurationClassBeanDefinitionReader.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Register the {@link Configuration} class itself as a bean definition.
 */
private void registerBeanDefinitionForImportedConfigurationClass(ConfigurationClass configClass) {
	AnnotationMetadata metadata = configClass.getMetadata();
	AnnotatedGenericBeanDefinition configBeanDef = new AnnotatedGenericBeanDefinition(metadata);

	ScopeMetadata scopeMetadata = scopeMetadataResolver.resolveScopeMetadata(configBeanDef);
	configBeanDef.setScope(scopeMetadata.getScopeName());
	String configBeanName = this.importBeanNameGenerator.generateBeanName(configBeanDef, this.registry);
	AnnotationConfigUtils.processCommonDefinitionAnnotations(configBeanDef, metadata);

	BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(configBeanDef, configBeanName);
	definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
	this.registry.registerBeanDefinition(definitionHolder.getBeanName(), definitionHolder.getBeanDefinition());
	configClass.setBeanName(configBeanName);

	if (logger.isTraceEnabled()) {
		logger.trace("Registered bean definition for imported class '" + configBeanName + "'");
	}
}
 
Example #7
Source File: JsfCdiToSpringApplicationBeanFactoryPostProcessorIT.java    From joinfaces with Apache License 2.0 6 votes vote down vote up
@Test
public void testViewScopedClass() {
	GenericApplicationContext acx = new GenericApplicationContext();
	AnnotationConfigUtils.registerAnnotationConfigProcessors(acx);

	acx.registerBeanDefinition("viewScopedClass", new AnnotatedGenericBeanDefinition(
		new StandardAnnotationMetadata(ViewScopedClass.class)));
	acx.registerBeanDefinition("scopedBeansConfiguration", new RootBeanDefinition(
		ScopedBeansConfiguration.class));
	acx.addBeanFactoryPostProcessor(JsfScopeAnnotationsAutoConfiguration.jsfScopeAnnotationsConfigurer(acx.getEnvironment()));
	acx.addBeanFactoryPostProcessor(CdiScopeAnnotationsAutoConfiguration.cdiScopeAnnotationsConfigurer(acx.getEnvironment()));
	acx.refresh();

	assertThat(acx.getBeanDefinition("viewScopedClass").getScope())
		.isEqualTo(ViewScope.SCOPE_VIEW);
	assertThat(acx.getBeanDefinition("viewScopedBean").getScope())
		.isEqualTo(ViewScope.SCOPE_VIEW);
}
 
Example #8
Source File: JsfCdiToSpringApplicationBeanFactoryPostProcessorIT.java    From joinfaces with Apache License 2.0 6 votes vote down vote up
@Test
public void testSessionScopedClass() {
	GenericApplicationContext acx = new GenericApplicationContext();
	AnnotationConfigUtils.registerAnnotationConfigProcessors(acx);

	acx.registerBeanDefinition("sessionScopedClass", new AnnotatedGenericBeanDefinition(
		new StandardAnnotationMetadata(SessionScopedClass.class)));
	acx.registerBeanDefinition("scopedBeansConfiguration", new RootBeanDefinition(
		ScopedBeansConfiguration.class));
	acx.addBeanFactoryPostProcessor(JsfScopeAnnotationsAutoConfiguration.jsfScopeAnnotationsConfigurer(acx.getEnvironment()));
	acx.addBeanFactoryPostProcessor(CdiScopeAnnotationsAutoConfiguration.cdiScopeAnnotationsConfigurer(acx.getEnvironment()));
	acx.refresh();

	assertThat(acx.getBeanDefinition("sessionScopedClass").getScope())
		.isEqualTo(WebApplicationContext.SCOPE_SESSION);
	assertThat(acx.getBeanDefinition("sessionScopedBean").getScope())
		.isEqualTo(WebApplicationContext.SCOPE_SESSION);
}
 
Example #9
Source File: ConfigurationClassBeanDefinitionReader.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Register the {@link Configuration} class itself as a bean definition.
 */
private void registerBeanDefinitionForImportedConfigurationClass(ConfigurationClass configClass) {
	AnnotationMetadata metadata = configClass.getMetadata();
	AnnotatedGenericBeanDefinition configBeanDef = new AnnotatedGenericBeanDefinition(metadata);

	ScopeMetadata scopeMetadata = scopeMetadataResolver.resolveScopeMetadata(configBeanDef);
	configBeanDef.setScope(scopeMetadata.getScopeName());
	String configBeanName = this.importBeanNameGenerator.generateBeanName(configBeanDef, this.registry);
	AnnotationConfigUtils.processCommonDefinitionAnnotations(configBeanDef, metadata);

	BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(configBeanDef, configBeanName);
	definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
	this.registry.registerBeanDefinition(definitionHolder.getBeanName(), definitionHolder.getBeanDefinition());
	configClass.setBeanName(configBeanName);

	if (logger.isTraceEnabled()) {
		logger.trace("Registered bean definition for imported class '" + configBeanName + "'");
	}
}
 
Example #10
Source File: ClassPathScanningCandidateComponentProviderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void excludeFilterWithIndex() {
	ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
	provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
	provider.addExcludeFilter(new RegexPatternTypeFilter(Pattern.compile(TEST_BASE_PACKAGE + ".*Named.*")));
	testExclude(provider, AnnotatedGenericBeanDefinition.class);
}
 
Example #11
Source File: AnnotationBeanNameGeneratorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void generateBeanNameWithNamedComponent() {
	BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
	AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentWithName.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));
	assertEquals("walden", beanName);
}
 
Example #12
Source File: AnnotationBeanNameGeneratorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * @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);
}
 
Example #13
Source File: AnnotationBeanNameGeneratorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * @since 4.0.1
 * @see https://jira.spring.io/browse/SPR-11360
 */
@Test
public void generateBeanNameFromComposedControllerAnnotationWithBlankName() {
	BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
	AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComposedControllerAnnotationWithBlankName.class);
	String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
	String expectedGeneratedBeanName = this.beanNameGenerator.buildDefaultBeanName(bd);
	assertEquals(expectedGeneratedBeanName, beanName);
}
 
Example #14
Source File: AnnotationBeanNameGeneratorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void generateBeanNameFromMetaComponentWithStringValue() {
	BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
	AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentFromStringMeta.class);
	String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
	assertEquals("henry", beanName);
}
 
Example #15
Source File: AnnotationBeanNameGeneratorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void generateBeanNameWithAnonymousComponentYieldsGeneratedBeanName() {
	BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
	AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnonymousComponent.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);
}
 
Example #16
Source File: AnnotationBeanNameGeneratorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #17
Source File: AnnotationBeanNameGeneratorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void generateBeanNameWithDefaultNamedComponent() {
	BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
	AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(DefaultNamedComponent.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));
	assertEquals("thoreau", beanName);
}
 
Example #18
Source File: AnnotationBeanNameGeneratorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void generateBeanNameFromMetaComponentWithNonStringValue() {
	BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
	AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentFromNonStringMeta.class);
	String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
	assertEquals("annotationBeanNameGeneratorTests.ComponentFromNonStringMeta", beanName);
}
 
Example #19
Source File: AnnotatedBeanDefinitionReader.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Register a bean from the given bean class, deriving its metadata from
 * class-declared annotations.
 * @param annotatedClass the class of the bean
 * @param name an explicit name for the bean
 * @param supplier a callback for creating an instance of the bean
 * (may be {@code null})
 * @param qualifiers specific qualifier annotations to consider, if any,
 * in addition to qualifiers at the bean class level
 * @param customizers one or more callbacks for customizing the factory's
 * {@link BeanDefinition}, e.g. setting a lazy-init or primary flag
 * @since 5.0
 */
private <T> void doRegisterBean(Class<T> annotatedClass, @Nullable String name,
		@Nullable Class<? extends Annotation>[] qualifiers, @Nullable Supplier<T> supplier,
		@Nullable BeanDefinitionCustomizer[] customizers) {

	AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);
	if (this.conditionEvaluator.shouldSkip(abd.getMetadata())) {
		return;
	}

	abd.setInstanceSupplier(supplier);
	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 (customizers != null) {
		for (BeanDefinitionCustomizer customizer : customizers) {
			customizer.customize(abd);
		}
	}

	BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(abd, beanName);
	definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
	BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, this.registry);
}
 
Example #20
Source File: AnnotatedBeanDefinitionReader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Register a bean from the given bean class, deriving its metadata from
 * class-declared annotations.
 * @param annotatedClass the class of the bean
 * @param name an explicit name for the bean
 * @param qualifiers specific qualifier annotations to consider,
 * in addition to qualifiers at the bean class level
 */
@SuppressWarnings("unchecked")
public void registerBean(Class<?> annotatedClass, String name, Class<? extends Annotation>... qualifiers) {
	AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);
	if (this.conditionEvaluator.shouldSkip(abd.getMetadata())) {
		return;
	}

	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));
			}
		}
	}

	BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(abd, beanName);
	definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
	BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, this.registry);
}
 
Example #21
Source File: AnnotationBeanNameGeneratorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void generateBeanNameWithNamedComponent() {
	BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
	AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentWithName.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));
	assertEquals("walden", beanName);
}
 
Example #22
Source File: SpringInitializer.java    From Mycat-openEP with Apache License 2.0 5 votes vote down vote up
private static void initAnnotatedConf(GenericApplicationContext context){
	Class componentScanAnnotated=ProcessInfo.getAnnotationInitClass();
	if(componentScanAnnotated!=null){
		AnnotatedGenericBeanDefinition def=new AnnotatedGenericBeanDefinition(ProcessInfo.getAnnotationInitClass());
		AnnotatedBeanDefinitionReader reader=new AnnotatedBeanDefinitionReader(context);
		AnnotationScopeMetadataResolver resolver=new AnnotationScopeMetadataResolver();
		resolver.resolveScopeMetadata(def);
		reader.setScopeMetadataResolver(resolver);
	}
}
 
Example #23
Source File: AnnotationBeanNameGeneratorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * @since 4.0.1
 * @see https://jira.spring.io/browse/SPR-11360
 */
@Test
public void generateBeanNameFromComposedControllerAnnotationWithBlankName() {
	BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
	AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComposedControllerAnnotationWithBlankName.class);
	String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
	String expectedGeneratedBeanName = this.beanNameGenerator.buildDefaultBeanName(bd);
	assertEquals(expectedGeneratedBeanName, beanName);
}
 
Example #24
Source File: AnnotationBeanNameGeneratorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * @since 4.0.1
 * @see https://jira.spring.io/browse/SPR-11360
 */
@Test
public void generateBeanNameFromComposedControllerAnnotationWithoutName() {
	BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
	AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComposedControllerAnnotationWithoutName.class);
	String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
	String expectedGeneratedBeanName = this.beanNameGenerator.buildDefaultBeanName(bd);
	assertEquals(expectedGeneratedBeanName, beanName);
}
 
Example #25
Source File: AnnotationBeanNameGeneratorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void generateBeanNameFromMetaComponentWithNonStringValue() {
	BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
	AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentFromNonStringMeta.class);
	String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
	assertEquals("annotationBeanNameGeneratorTests.ComponentFromNonStringMeta", beanName);
}
 
Example #26
Source File: AnnotationBeanNameGeneratorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void generateBeanNameFromMetaComponentWithStringValue() {
	BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
	AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentFromStringMeta.class);
	String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
	assertEquals("henry", beanName);
}
 
Example #27
Source File: AnnotationScopeMetadataResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void customRequestScopeWithAttributeViaAsm() throws IOException {
	MetadataReaderFactory readerFactory = new SimpleMetadataReaderFactory();
	MetadataReader reader = readerFactory.getMetadataReader(AnnotatedWithCustomRequestScopeWithAttributeOverride.class.getName());
	AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(reader.getAnnotationMetadata());
	ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
	assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
	assertEquals("request", scopeMetadata.getScopeName());
	assertEquals(TARGET_CLASS, scopeMetadata.getScopedProxyMode());
}
 
Example #28
Source File: AnnotationBeanNameGeneratorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void generateBeanNameWithAnonymousComponentYieldsGeneratedBeanName() {
	BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
	AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnonymousComponent.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);
}
 
Example #29
Source File: AnnotationBeanNameGeneratorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);
}
 
Example #30
Source File: AnnotationBeanNameGeneratorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void generateBeanNameWithDefaultNamedComponent() {
	BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
	AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(DefaultNamedComponent.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));
	assertEquals("thoreau", beanName);
}