Polishing
This commit is contained in:
parent
8d4953d8d6
commit
7ffeb59b40
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -610,13 +610,10 @@ class ConstructorResolver {
|
|||
String argDesc = StringUtils.collectionToCommaDelimitedString(argTypes);
|
||||
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
|
||||
"No matching factory method found on class [" + factoryClass.getName() + "]: " +
|
||||
(mbd.getFactoryBeanName() != null ?
|
||||
"factory bean '" + mbd.getFactoryBeanName() + "'; " : "") +
|
||||
(mbd.getFactoryBeanName() != null ? "factory bean '" + mbd.getFactoryBeanName() + "'; " : "") +
|
||||
"factory method '" + mbd.getFactoryMethodName() + "(" + argDesc + ")'. " +
|
||||
"Check that a method with the specified name " +
|
||||
(minNrOfArgs > 0 ? "and arguments " : "") +
|
||||
"exists and that it is " +
|
||||
(isStatic ? "static" : "non-static") + ".");
|
||||
"Check that a method with the specified name " + (minNrOfArgs > 0 ? "and arguments " : "") +
|
||||
"exists and that it is " + (isStatic ? "static" : "non-static") + ".");
|
||||
}
|
||||
else if (void.class == factoryMethodToUse.getReturnType()) {
|
||||
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -567,16 +567,16 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
|
|||
*/
|
||||
protected void destroyBean(String beanName, @Nullable DisposableBean bean) {
|
||||
// Trigger destruction of dependent beans first...
|
||||
Set<String> dependencies;
|
||||
Set<String> dependentBeanNames;
|
||||
synchronized (this.dependentBeanMap) {
|
||||
// Within full synchronization in order to guarantee a disconnected Set
|
||||
dependencies = this.dependentBeanMap.remove(beanName);
|
||||
dependentBeanNames = this.dependentBeanMap.remove(beanName);
|
||||
}
|
||||
if (dependencies != null) {
|
||||
if (dependentBeanNames != null) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Retrieved dependent beans for bean '" + beanName + "': " + dependencies);
|
||||
logger.trace("Retrieved dependent beans for bean '" + beanName + "': " + dependentBeanNames);
|
||||
}
|
||||
for (String dependentBeanName : dependencies) {
|
||||
for (String dependentBeanName : dependentBeanNames) {
|
||||
destroySingleton(dependentBeanName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -73,7 +73,6 @@ final class ConfigurationClass {
|
|||
* Create a new {@link ConfigurationClass} with the given name.
|
||||
* @param metadataReader reader used to parse the underlying {@link Class}
|
||||
* @param beanName must not be {@code null}
|
||||
* @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass)
|
||||
*/
|
||||
ConfigurationClass(MetadataReader metadataReader, String beanName) {
|
||||
Assert.notNull(beanName, "Bean name must not be null");
|
||||
|
|
@ -87,10 +86,10 @@ final class ConfigurationClass {
|
|||
* using the {@link Import} annotation or automatically processed as a nested
|
||||
* configuration class (if importedBy is not {@code null}).
|
||||
* @param metadataReader reader used to parse the underlying {@link Class}
|
||||
* @param importedBy the configuration class importing this one or {@code null}
|
||||
* @param importedBy the configuration class importing this one
|
||||
* @since 3.1.1
|
||||
*/
|
||||
ConfigurationClass(MetadataReader metadataReader, @Nullable ConfigurationClass importedBy) {
|
||||
ConfigurationClass(MetadataReader metadataReader, ConfigurationClass importedBy) {
|
||||
this.metadata = metadataReader.getAnnotationMetadata();
|
||||
this.resource = metadataReader.getResource();
|
||||
this.importedBy.add(importedBy);
|
||||
|
|
@ -100,7 +99,6 @@ final class ConfigurationClass {
|
|||
* Create a new {@link ConfigurationClass} with the given name.
|
||||
* @param clazz the underlying {@link Class} to represent
|
||||
* @param beanName name of the {@code @Configuration} class bean
|
||||
* @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass)
|
||||
*/
|
||||
ConfigurationClass(Class<?> clazz, String beanName) {
|
||||
Assert.notNull(beanName, "Bean name must not be null");
|
||||
|
|
@ -114,10 +112,10 @@ final class ConfigurationClass {
|
|||
* using the {@link Import} annotation or automatically processed as a nested
|
||||
* configuration class (if imported is {@code true}).
|
||||
* @param clazz the underlying {@link Class} to represent
|
||||
* @param importedBy the configuration class importing this one (or {@code null})
|
||||
* @param importedBy the configuration class importing this one
|
||||
* @since 3.1.1
|
||||
*/
|
||||
ConfigurationClass(Class<?> clazz, @Nullable ConfigurationClass importedBy) {
|
||||
ConfigurationClass(Class<?> clazz, ConfigurationClass importedBy) {
|
||||
this.metadata = AnnotationMetadata.introspect(clazz);
|
||||
this.resource = new DescriptiveResource(clazz.getName());
|
||||
this.importedBy.add(importedBy);
|
||||
|
|
@ -127,7 +125,6 @@ final class ConfigurationClass {
|
|||
* Create a new {@link ConfigurationClass} with the given name.
|
||||
* @param metadata the metadata for the underlying class to represent
|
||||
* @param beanName name of the {@code @Configuration} class bean
|
||||
* @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass)
|
||||
*/
|
||||
ConfigurationClass(AnnotationMetadata metadata, String beanName) {
|
||||
Assert.notNull(beanName, "Bean name must not be null");
|
||||
|
|
@ -149,12 +146,12 @@ final class ConfigurationClass {
|
|||
return ClassUtils.getShortName(getMetadata().getClassName());
|
||||
}
|
||||
|
||||
void setBeanName(String beanName) {
|
||||
void setBeanName(@Nullable String beanName) {
|
||||
this.beanName = beanName;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getBeanName() {
|
||||
String getBeanName() {
|
||||
return this.beanName;
|
||||
}
|
||||
|
||||
|
|
@ -164,7 +161,7 @@ final class ConfigurationClass {
|
|||
* @since 3.1.1
|
||||
* @see #getImportedBy()
|
||||
*/
|
||||
public boolean isImported() {
|
||||
boolean isImported() {
|
||||
return !this.importedBy.isEmpty();
|
||||
}
|
||||
|
||||
|
|
@ -198,6 +195,10 @@ final class ConfigurationClass {
|
|||
this.importedResources.put(importedResource, readerClass);
|
||||
}
|
||||
|
||||
Map<String, Class<? extends BeanDefinitionReader>> getImportedResources() {
|
||||
return this.importedResources;
|
||||
}
|
||||
|
||||
void addImportBeanDefinitionRegistrar(ImportBeanDefinitionRegistrar registrar, AnnotationMetadata importingClassMetadata) {
|
||||
this.importBeanDefinitionRegistrars.put(registrar, importingClassMetadata);
|
||||
}
|
||||
|
|
@ -206,10 +207,6 @@ final class ConfigurationClass {
|
|||
return this.importBeanDefinitionRegistrars;
|
||||
}
|
||||
|
||||
Map<String, Class<? extends BeanDefinitionReader>> getImportedResources() {
|
||||
return this.importedResources;
|
||||
}
|
||||
|
||||
void validate(ProblemReporter problemReporter) {
|
||||
Map<String, Object> attributes = this.metadata.getAnnotationAttributes(Configuration.class.getName());
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
|
||||
/**
|
||||
* Tests regarding overloading and overriding of bean methods.
|
||||
*
|
||||
* <p>Related to SPR-6618.
|
||||
*
|
||||
* @author Chris Beams
|
||||
|
|
@ -41,6 +42,7 @@ public class BeanMethodPolymorphismTests {
|
|||
@Test
|
||||
void beanMethodDetectedOnSuperClass() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
|
||||
|
||||
assertThat(ctx.getBean("testBean", BaseTestBean.class)).isNotNull();
|
||||
}
|
||||
|
||||
|
|
@ -50,6 +52,7 @@ public class BeanMethodPolymorphismTests {
|
|||
ctx.register(OverridingConfig.class);
|
||||
ctx.setAllowBeanDefinitionOverriding(false);
|
||||
ctx.refresh();
|
||||
|
||||
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")).isFalse();
|
||||
assertThat(ctx.getBean("testBean", BaseTestBean.class).toString()).isEqualTo("overridden");
|
||||
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")).isTrue();
|
||||
|
|
@ -61,6 +64,7 @@ public class BeanMethodPolymorphismTests {
|
|||
ctx.registerBeanDefinition("config", new RootBeanDefinition(OverridingConfig.class.getName()));
|
||||
ctx.setAllowBeanDefinitionOverriding(false);
|
||||
ctx.refresh();
|
||||
|
||||
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")).isFalse();
|
||||
assertThat(ctx.getBean("testBean", BaseTestBean.class).toString()).isEqualTo("overridden");
|
||||
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")).isTrue();
|
||||
|
|
@ -72,6 +76,7 @@ public class BeanMethodPolymorphismTests {
|
|||
ctx.register(NarrowedOverridingConfig.class);
|
||||
ctx.setAllowBeanDefinitionOverriding(false);
|
||||
ctx.refresh();
|
||||
|
||||
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")).isFalse();
|
||||
assertThat(ctx.getBean("testBean", BaseTestBean.class).toString()).isEqualTo("overridden");
|
||||
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")).isTrue();
|
||||
|
|
@ -83,6 +88,7 @@ public class BeanMethodPolymorphismTests {
|
|||
ctx.registerBeanDefinition("config", new RootBeanDefinition(NarrowedOverridingConfig.class.getName()));
|
||||
ctx.setAllowBeanDefinitionOverriding(false);
|
||||
ctx.refresh();
|
||||
|
||||
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")).isFalse();
|
||||
assertThat(ctx.getBean("testBean", BaseTestBean.class).toString()).isEqualTo("overridden");
|
||||
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")).isTrue();
|
||||
|
|
@ -94,6 +100,7 @@ public class BeanMethodPolymorphismTests {
|
|||
ctx.register(ConfigWithOverloading.class);
|
||||
ctx.setAllowBeanDefinitionOverriding(false);
|
||||
ctx.refresh();
|
||||
|
||||
assertThat(ctx.getBean(String.class)).isEqualTo("regular");
|
||||
}
|
||||
|
||||
|
|
@ -104,6 +111,7 @@ public class BeanMethodPolymorphismTests {
|
|||
ctx.getDefaultListableBeanFactory().registerSingleton("anInt", 5);
|
||||
ctx.setAllowBeanDefinitionOverriding(false);
|
||||
ctx.refresh();
|
||||
|
||||
assertThat(ctx.getBean(String.class)).isEqualTo("overloaded5");
|
||||
}
|
||||
|
||||
|
|
@ -113,6 +121,7 @@ public class BeanMethodPolymorphismTests {
|
|||
ctx.register(ConfigWithOverloadingAndAdditionalMetadata.class);
|
||||
ctx.setAllowBeanDefinitionOverriding(false);
|
||||
ctx.refresh();
|
||||
|
||||
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("aString")).isFalse();
|
||||
assertThat(ctx.getBean(String.class)).isEqualTo("regular");
|
||||
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("aString")).isTrue();
|
||||
|
|
@ -125,6 +134,7 @@ public class BeanMethodPolymorphismTests {
|
|||
ctx.getDefaultListableBeanFactory().registerSingleton("anInt", 5);
|
||||
ctx.setAllowBeanDefinitionOverriding(false);
|
||||
ctx.refresh();
|
||||
|
||||
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("aString")).isFalse();
|
||||
assertThat(ctx.getBean(String.class)).isEqualTo("overloaded5");
|
||||
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("aString")).isTrue();
|
||||
|
|
@ -136,18 +146,19 @@ public class BeanMethodPolymorphismTests {
|
|||
ctx.register(SubConfig.class);
|
||||
ctx.setAllowBeanDefinitionOverriding(false);
|
||||
ctx.refresh();
|
||||
|
||||
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("aString")).isFalse();
|
||||
assertThat(ctx.getBean(String.class)).isEqualTo("overloaded5");
|
||||
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("aString")).isTrue();
|
||||
}
|
||||
|
||||
// SPR-11025
|
||||
@Test
|
||||
@Test // SPR-11025
|
||||
void beanMethodOverloadingWithInheritanceAndList() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(SubConfigWithList.class);
|
||||
ctx.setAllowBeanDefinitionOverriding(false);
|
||||
ctx.refresh();
|
||||
|
||||
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("aString")).isFalse();
|
||||
assertThat(ctx.getBean(String.class)).isEqualTo("overloaded5");
|
||||
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("aString")).isTrue();
|
||||
|
|
@ -161,6 +172,7 @@ public class BeanMethodPolymorphismTests {
|
|||
@Test
|
||||
void beanMethodShadowing() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ShadowConfig.class);
|
||||
|
||||
assertThat(ctx.getBean(String.class)).isEqualTo("shadow");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -80,15 +80,16 @@ class ComponentScanAnnotationIntegrationTests {
|
|||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.scan(example.scannable.PackageMarker.class.getPackage().getName());
|
||||
ctx.refresh();
|
||||
|
||||
assertContextContainsBean(ctx, "fooServiceImpl");
|
||||
}
|
||||
|
||||
@Test
|
||||
void viaContextRegistration() {
|
||||
AnnotationConfigApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(ComponentScanAnnotatedConfig.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(ComponentScanAnnotatedConfig.class);
|
||||
ctx.getBean(ComponentScanAnnotatedConfig.class);
|
||||
ctx.getBean(TestBean.class);
|
||||
|
||||
assertThat(ctx.containsBeanDefinition("componentScanAnnotatedConfig")).as("config class bean not found").isTrue();
|
||||
assertThat(ctx.containsBean("fooServiceImpl")).as("@ComponentScan annotated @Configuration class registered directly against " +
|
||||
"AnnotationConfigApplicationContext did not trigger component scanning as expected").isTrue();
|
||||
|
|
@ -96,10 +97,10 @@ class ComponentScanAnnotationIntegrationTests {
|
|||
|
||||
@Test
|
||||
void viaContextRegistration_WithValueAttribute() {
|
||||
AnnotationConfigApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(ComponentScanAnnotatedConfig_WithValueAttribute.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(ComponentScanAnnotatedConfig_WithValueAttribute.class);
|
||||
ctx.getBean(ComponentScanAnnotatedConfig_WithValueAttribute.class);
|
||||
ctx.getBean(TestBean.class);
|
||||
|
||||
assertThat(ctx.containsBeanDefinition("componentScanAnnotatedConfig_WithValueAttribute")).as("config class bean not found").isTrue();
|
||||
assertThat(ctx.containsBean("fooServiceImpl")).as("@ComponentScan annotated @Configuration class registered directly against " +
|
||||
"AnnotationConfigApplicationContext did not trigger component scanning as expected").isTrue();
|
||||
|
|
@ -107,9 +108,9 @@ class ComponentScanAnnotationIntegrationTests {
|
|||
|
||||
@Test
|
||||
void viaContextRegistration_FromPackageOfConfigClass() {
|
||||
AnnotationConfigApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(ComponentScanAnnotatedConfigWithImplicitBasePackage.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(ComponentScanAnnotatedConfigWithImplicitBasePackage.class);
|
||||
ctx.getBean(ComponentScanAnnotatedConfigWithImplicitBasePackage.class);
|
||||
|
||||
assertThat(ctx.containsBeanDefinition("componentScanAnnotatedConfigWithImplicitBasePackage")).as("config class bean not found").isTrue();
|
||||
assertThat(ctx.containsBean("scannedComponent")).as("@ComponentScan annotated @Configuration class registered directly against " +
|
||||
"AnnotationConfigApplicationContext did not trigger component scanning as expected").isTrue();
|
||||
|
|
@ -118,11 +119,12 @@ class ComponentScanAnnotationIntegrationTests {
|
|||
|
||||
@Test
|
||||
void viaContextRegistration_WithComposedAnnotation() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ComposedAnnotationConfig.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(ComposedAnnotationConfig.class);
|
||||
ctx.getBean(ComposedAnnotationConfig.class);
|
||||
ctx.getBean(SimpleComponent.class);
|
||||
ctx.getBean(ClassWithNestedComponents.NestedComponent.class);
|
||||
ctx.getBean(ClassWithNestedComponents.OtherNestedComponent.class);
|
||||
|
||||
assertThat(ctx.containsBeanDefinition("componentScanAnnotationIntegrationTests.ComposedAnnotationConfig")).as("config class bean not found").isTrue();
|
||||
assertThat(ctx.containsBean("simpleComponent")).as("@ComponentScan annotated @Configuration class registered directly against " +
|
||||
"AnnotationConfigApplicationContext did not trigger component scanning as expected").isTrue();
|
||||
|
|
@ -132,6 +134,7 @@ class ComponentScanAnnotationIntegrationTests {
|
|||
void multipleComposedComponentScanAnnotations() { // gh-30941
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(MultipleComposedAnnotationsConfig.class);
|
||||
ctx.getBean(MultipleComposedAnnotationsConfig.class);
|
||||
|
||||
assertContextContainsBean(ctx, "componentScanAnnotationIntegrationTests.MultipleComposedAnnotationsConfig");
|
||||
assertContextContainsBean(ctx, "simpleComponent");
|
||||
assertContextContainsBean(ctx, "barComponent");
|
||||
|
|
@ -143,7 +146,6 @@ class ComponentScanAnnotationIntegrationTests {
|
|||
|
||||
assertContextContainsBean(ctx, "componentScanAnnotationIntegrationTests.LocalAnnotationOverridesMultipleMetaAnnotationsConfig");
|
||||
assertContextContainsBean(ctx, "barComponent");
|
||||
|
||||
assertContextDoesNotContainBean(ctx, "simpleComponent");
|
||||
assertContextDoesNotContainBean(ctx, "configurableComponent");
|
||||
}
|
||||
|
|
@ -154,7 +156,6 @@ class ComponentScanAnnotationIntegrationTests {
|
|||
|
||||
assertContextContainsBean(ctx, "componentScanAnnotationIntegrationTests.LocalAnnotationOverridesMultipleComposedAnnotationsConfig");
|
||||
assertContextContainsBean(ctx, "barComponent");
|
||||
|
||||
assertContextDoesNotContainBean(ctx, "simpleComponent");
|
||||
assertContextDoesNotContainBean(ctx, "configurableComponent");
|
||||
}
|
||||
|
|
@ -166,7 +167,6 @@ class ComponentScanAnnotationIntegrationTests {
|
|||
assertContextContainsBean(ctx, "componentScanAnnotationIntegrationTests.LocalRepeatedAnnotationsOverrideComposedAnnotationsConfig");
|
||||
assertContextContainsBean(ctx, "barComponent");
|
||||
assertContextContainsBean(ctx, "configurableComponent");
|
||||
|
||||
assertContextDoesNotContainBean(ctx, "simpleComponent");
|
||||
}
|
||||
|
||||
|
|
@ -177,7 +177,6 @@ class ComponentScanAnnotationIntegrationTests {
|
|||
assertContextContainsBean(ctx, "componentScanAnnotationIntegrationTests.LocalRepeatedAnnotationsInContainerOverrideComposedAnnotationsConfig");
|
||||
assertContextContainsBean(ctx, "barComponent");
|
||||
assertContextContainsBean(ctx, "configurableComponent");
|
||||
|
||||
assertContextDoesNotContainBean(ctx, "simpleComponent");
|
||||
}
|
||||
|
||||
|
|
@ -188,10 +187,12 @@ class ComponentScanAnnotationIntegrationTests {
|
|||
genericBeanDefinition(ComponentScanAnnotatedConfig.class).getBeanDefinition());
|
||||
bf.registerBeanDefinition("configurationClassPostProcessor",
|
||||
genericBeanDefinition(ConfigurationClassPostProcessor.class).getBeanDefinition());
|
||||
|
||||
GenericApplicationContext ctx = new GenericApplicationContext(bf);
|
||||
ctx.refresh();
|
||||
ctx.getBean(ComponentScanAnnotatedConfig.class);
|
||||
ctx.getBean(TestBean.class);
|
||||
|
||||
assertThat(ctx.containsBeanDefinition("componentScanAnnotatedConfig")).as("config class bean not found").isTrue();
|
||||
assertThat(ctx.containsBean("fooServiceImpl")).as("@ComponentScan annotated @Configuration class registered as bean " +
|
||||
"definition did not trigger component scanning as expected").isTrue();
|
||||
|
|
@ -206,7 +207,8 @@ class ComponentScanAnnotationIntegrationTests {
|
|||
|
||||
@Test
|
||||
void withScopeResolver() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ComponentScanWithScopeResolver.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(ComponentScanWithScopeResolver.class);
|
||||
|
||||
// custom scope annotation makes the bean prototype scoped. subsequent calls
|
||||
// to getBean should return distinct instances.
|
||||
assertThat(ctx.getBean(CustomScopeAnnotationBean.class)).isNotSameAs(ctx.getBean(CustomScopeAnnotationBean.class));
|
||||
|
|
@ -215,7 +217,8 @@ class ComponentScanAnnotationIntegrationTests {
|
|||
|
||||
@Test
|
||||
void multiComponentScan() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(MultiComponentScan.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(MultiComponentScan.class);
|
||||
|
||||
assertThat(ctx.getBean(CustomScopeAnnotationBean.class)).isNotSameAs(ctx.getBean(CustomScopeAnnotationBean.class));
|
||||
assertContextContainsBean(ctx, "scannedComponent");
|
||||
}
|
||||
|
|
@ -223,14 +226,16 @@ class ComponentScanAnnotationIntegrationTests {
|
|||
@Test
|
||||
void withCustomTypeFilter() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ComponentScanWithCustomTypeFilter.class);
|
||||
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("componentScanParserTests.KustomAnnotationAutowiredBean")).isFalse();
|
||||
|
||||
assertThat(ctx.getBeanFactory().containsSingleton("componentScanParserTests.KustomAnnotationAutowiredBean")).isFalse();
|
||||
KustomAnnotationAutowiredBean testBean = ctx.getBean("componentScanParserTests.KustomAnnotationAutowiredBean", KustomAnnotationAutowiredBean.class);
|
||||
assertThat(testBean.getDependency()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void withAwareTypeFilter() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ComponentScanWithAwareTypeFilter.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(ComponentScanWithAwareTypeFilter.class);
|
||||
|
||||
assertThat(ctx.getEnvironment().matchesProfiles("the-filter-ran")).isTrue();
|
||||
}
|
||||
|
||||
|
|
@ -240,6 +245,7 @@ class ComponentScanAnnotationIntegrationTests {
|
|||
ctx.register(ComponentScanWithScopedProxy.class);
|
||||
ctx.getBeanFactory().registerScope("myScope", new SimpleMapScope());
|
||||
ctx.refresh();
|
||||
|
||||
// should cast to the interface
|
||||
FooService bean = (FooService) ctx.getBean("scopedProxyTestBean");
|
||||
// should be dynamic proxy
|
||||
|
|
@ -257,6 +263,7 @@ class ComponentScanAnnotationIntegrationTests {
|
|||
ctx.register(ComponentScanWithScopedProxyThroughRegex.class);
|
||||
ctx.getBeanFactory().registerScope("myScope", new SimpleMapScope());
|
||||
ctx.refresh();
|
||||
|
||||
// should cast to the interface
|
||||
FooService bean = (FooService) ctx.getBean("scopedProxyTestBean");
|
||||
// should be dynamic proxy
|
||||
|
|
@ -269,6 +276,7 @@ class ComponentScanAnnotationIntegrationTests {
|
|||
ctx.register(ComponentScanWithScopedProxyThroughAspectJPattern.class);
|
||||
ctx.getBeanFactory().registerScope("myScope", new SimpleMapScope());
|
||||
ctx.refresh();
|
||||
|
||||
// should cast to the interface
|
||||
FooService bean = (FooService) ctx.getBean("scopedProxyTestBean");
|
||||
// should be dynamic proxy
|
||||
|
|
@ -277,16 +285,16 @@ class ComponentScanAnnotationIntegrationTests {
|
|||
|
||||
@Test
|
||||
void withMultipleAnnotationIncludeFilters1() {
|
||||
AnnotationConfigApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(ComponentScanWithMultipleAnnotationIncludeFilters1.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(ComponentScanWithMultipleAnnotationIncludeFilters1.class);
|
||||
|
||||
ctx.getBean(DefaultNamedComponent.class); // @CustomStereotype-annotated
|
||||
ctx.getBean(MessageBean.class); // @CustomComponent-annotated
|
||||
}
|
||||
|
||||
@Test
|
||||
void withMultipleAnnotationIncludeFilters2() {
|
||||
AnnotationConfigApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(ComponentScanWithMultipleAnnotationIncludeFilters2.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(ComponentScanWithMultipleAnnotationIncludeFilters2.class);
|
||||
|
||||
ctx.getBean(DefaultNamedComponent.class); // @CustomStereotype-annotated
|
||||
ctx.getBean(MessageBean.class); // @CustomComponent-annotated
|
||||
}
|
||||
|
|
@ -296,25 +304,28 @@ class ComponentScanAnnotationIntegrationTests {
|
|||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ComponentScanWithMultipleAnnotationIncludeFilters3.class);
|
||||
ctx.refresh();
|
||||
|
||||
assertThat(ctx.getBean(DefaultNamedComponent.class).toString()).isEqualTo("overridden");
|
||||
}
|
||||
|
||||
@Test
|
||||
void withBeanMethodOverrideAndGeneralOverridingDisabled() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.getDefaultListableBeanFactory().setAllowBeanDefinitionOverriding(false);
|
||||
ctx.setAllowBeanDefinitionOverriding(false);
|
||||
ctx.register(ComponentScanWithMultipleAnnotationIncludeFilters3.class);
|
||||
ctx.refresh();
|
||||
|
||||
assertThat(ctx.getBean(DefaultNamedComponent.class).toString()).isEqualTo("overridden");
|
||||
}
|
||||
|
||||
@Test
|
||||
void withBasePackagesAndValueAlias() {
|
||||
AnnotationConfigApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(ComponentScanWithBasePackagesAndValueAlias.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(ComponentScanWithBasePackagesAndValueAlias.class);
|
||||
|
||||
assertContextContainsBean(ctx, "fooServiceImpl");
|
||||
}
|
||||
|
||||
|
||||
private static void assertContextContainsBean(ApplicationContext ctx, String beanName) {
|
||||
assertThat(ctx.containsBean(beanName)).as("context should contain bean " + beanName).isTrue();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue