org.springframework.beans.factory.config.BeanDefinitionCustomizer Java Examples
The following examples show how to use
org.springframework.beans.factory.config.BeanDefinitionCustomizer.
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: AnnotatedBeanDefinitionReader.java From spring-analysis-note with MIT License | 5 votes |
/** * 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 #2
Source File: BeanDefinitionBuilder.java From java-technology-stack with MIT License | 5 votes |
/** * Apply the given customizers to the underlying bean definition. * @since 5.0 */ public BeanDefinitionBuilder applyCustomizers(BeanDefinitionCustomizer... customizers) { for (BeanDefinitionCustomizer customizer : customizers) { customizer.customize(this.beanDefinition); } return this; }
Example #3
Source File: BeanDefinitionBuilder.java From spring-analysis-note with MIT License | 5 votes |
/** * Apply the given customizers to the underlying bean definition. * @since 5.0 */ public BeanDefinitionBuilder applyCustomizers(BeanDefinitionCustomizer... customizers) { for (BeanDefinitionCustomizer customizer : customizers) { customizer.customize(this.beanDefinition); } return this; }
Example #4
Source File: AnnotatedBeanDefinitionReader.java From java-technology-stack with MIT License | 5 votes |
/** * 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, @Nullable Supplier<T> instanceSupplier, @Nullable String name, @Nullable 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)); } } } 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); }
Example #5
Source File: BeanDefinitionDsl.java From spring-fu with Apache License 2.0 | 4 votes |
/** * Declare a bean definition from the given bean name, class and supplier. */ public <T> BeanDefinitionDsl bean(String beanName, Class<T> beanClass, Supplier<T> supplier, BeanDefinitionCustomizer... customizers) { this.context.registerBean(beanName, beanClass, supplier, customizers); return this; }
Example #6
Source File: BeanDefinitionDsl.java From spring-fu with Apache License 2.0 | 4 votes |
/** * Declare a bean definition from the given bean class and supplier. */ public <T> BeanDefinitionDsl bean(Class<T> beanClass, Supplier<T> supplier, BeanDefinitionCustomizer... customizers) { String beanName = BeanDefinitionReaderUtils.uniqueBeanName(beanClass.getName(), context); this.context.registerBean(beanName, beanClass, supplier, customizers); return this; }
Example #7
Source File: BeanDefinitionDsl.java From spring-fu with Apache License 2.0 | 4 votes |
/** * Declare a bean definition from the given bean name and class. */ public <T> BeanDefinitionDsl bean(String beanName, Class<T> beanClass, BeanDefinitionCustomizer... customizers) { this.context.registerBean(beanName, beanClass); return this; }
Example #8
Source File: BeanDefinitionDsl.java From spring-fu with Apache License 2.0 | 4 votes |
/** * Declare a bean definition from the given bean class. */ public <T> BeanDefinitionDsl bean(Class<T> beanClass, BeanDefinitionCustomizer... customizers) { String beanName = BeanDefinitionReaderUtils.uniqueBeanName(beanClass.getName(), context); this.context.registerBean(beanName, beanClass, customizers); return this; }
Example #9
Source File: AnnotationConfigApplicationContext.java From java-technology-stack with MIT License | 4 votes |
@Override public <T> void registerBean(@Nullable String beanName, Class<T> beanClass, @Nullable Supplier<T> supplier, BeanDefinitionCustomizer... customizers) { this.reader.doRegisterBean(beanClass, supplier, beanName, null, customizers); }
Example #10
Source File: AnnotationConfigApplicationContext.java From spring-analysis-note with MIT License | 4 votes |
@Override public <T> void registerBean(@Nullable String beanName, Class<T> beanClass, @Nullable Supplier<T> supplier, BeanDefinitionCustomizer... customizers) { this.reader.registerBean(beanClass, beanName, supplier, customizers); }
Example #11
Source File: GenericApplicationContext.java From spring-analysis-note with MIT License | 3 votes |
/** * Register a bean from the given bean class, using the given supplier for * obtaining a new instance (typically declared as a lambda expression or * method reference), optionally customizing its bean definition metadata * (again typically declared as a lambda expression). * <p>This method can be overridden to adapt the registration mechanism for * all {@code registerBean} methods (since they all delegate to this one). * @param beanName the name of the bean (may be {@code null}) * @param beanClass the class of the bean * @param supplier a callback for creating an instance of the bean (in case * of {@code null}, resolving a public constructor to be autowired instead) * @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 */ public <T> void registerBean(@Nullable String beanName, Class<T> beanClass, @Nullable Supplier<T> supplier, BeanDefinitionCustomizer... customizers) { ClassDerivedBeanDefinition beanDefinition = new ClassDerivedBeanDefinition(beanClass); if (supplier != null) { beanDefinition.setInstanceSupplier(supplier); } for (BeanDefinitionCustomizer customizer : customizers) { customizer.customize(beanDefinition); } String nameToUse = (beanName != null ? beanName : beanClass.getName()); registerBeanDefinition(nameToUse, beanDefinition); }
Example #12
Source File: GenericApplicationContext.java From java-technology-stack with MIT License | 3 votes |
/** * Register a bean from the given bean class, using the given supplier for * obtaining a new instance (typically declared as a lambda expression or * method reference), optionally customizing its bean definition metadata * (again typically declared as a lambda expression or method reference). * <p>This method can be overridden to adapt the registration mechanism for * all {@code registerBean} methods (since they all delegate to this one). * @param beanName the name of the bean (may be {@code null}) * @param beanClass the class of the bean * @param supplier a callback for creating an instance of the bean (in case * of {@code null}, resolving a public constructor to be autowired instead) * @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 */ public <T> void registerBean(@Nullable String beanName, Class<T> beanClass, @Nullable Supplier<T> supplier, BeanDefinitionCustomizer... customizers) { ClassDerivedBeanDefinition beanDefinition = new ClassDerivedBeanDefinition(beanClass); if (supplier != null) { beanDefinition.setInstanceSupplier(supplier); } for (BeanDefinitionCustomizer customizer : customizers) { customizer.customize(beanDefinition); } String nameToUse = (beanName != null ? beanName : beanClass.getName()); registerBeanDefinition(nameToUse, beanDefinition); }
Example #13
Source File: GenericApplicationContext.java From java-technology-stack with MIT License | 2 votes |
/** * Register a bean from the given bean class, optionally customizing its * bean definition metadata (typically declared as a lambda expression * or method reference). * @param beanClass the class of the bean (resolving a public constructor * to be autowired, possibly simply the default constructor) * @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 * @see #registerBean(String, Class, Supplier, BeanDefinitionCustomizer...) */ public final <T> void registerBean(Class<T> beanClass, BeanDefinitionCustomizer... customizers) { registerBean(null, beanClass, null, customizers); }
Example #14
Source File: GenericApplicationContext.java From java-technology-stack with MIT License | 2 votes |
/** * Register a bean from the given bean class, using the given supplier for * obtaining a new instance (typically declared as a lambda expression or * method reference), optionally customizing its bean definition metadata * (again typically declared as a lambda expression or method reference). * @param beanName the name of the bean (may be {@code null}) * @param beanClass the class of the bean (resolving a public constructor * to be autowired, possibly simply the default constructor) * @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 * @see #registerBean(String, Class, Supplier, BeanDefinitionCustomizer...) */ public final <T> void registerBean( @Nullable String beanName, Class<T> beanClass, BeanDefinitionCustomizer... customizers) { registerBean(beanName, beanClass, null, customizers); }
Example #15
Source File: GenericApplicationContext.java From java-technology-stack with MIT License | 2 votes |
/** * Register a bean from the given bean class, using the given supplier for * obtaining a new instance (typically declared as a lambda expression or * method reference), optionally customizing its bean definition metadata * (again typically declared as a lambda expression or method reference). * @param beanClass the class of the bean * @param supplier a callback for creating an instance of the bean * @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 * @see #registerBean(String, Class, Supplier, BeanDefinitionCustomizer...) */ public final <T> void registerBean( Class<T> beanClass, Supplier<T> supplier, BeanDefinitionCustomizer... customizers) { registerBean(null, beanClass, supplier, customizers); }
Example #16
Source File: GenericApplicationContext.java From spring-analysis-note with MIT License | 2 votes |
/** * Register a bean from the given bean class, using the given supplier for * obtaining a new instance (typically declared as a lambda expression or * method reference), optionally customizing its bean definition metadata * (again typically declared as a lambda expression). * @param beanClass the class of the bean * @param supplier a callback for creating an instance of the bean * @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 * @see #registerBean(String, Class, Supplier, BeanDefinitionCustomizer...) */ public final <T> void registerBean( Class<T> beanClass, Supplier<T> supplier, BeanDefinitionCustomizer... customizers) { registerBean(null, beanClass, supplier, customizers); }
Example #17
Source File: GenericApplicationContext.java From spring-analysis-note with MIT License | 2 votes |
/** * Register a bean from the given bean class, optionally customizing its * bean definition metadata (typically declared as a lambda expression). * @param beanName the name of the bean (may be {@code null}) * @param beanClass the class of the bean (resolving a public constructor * to be autowired, possibly simply the default constructor) * @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 * @see #registerBean(String, Class, Supplier, BeanDefinitionCustomizer...) */ public final <T> void registerBean( @Nullable String beanName, Class<T> beanClass, BeanDefinitionCustomizer... customizers) { registerBean(beanName, beanClass, null, customizers); }
Example #18
Source File: GenericApplicationContext.java From spring-analysis-note with MIT License | 2 votes |
/** * Register a bean from the given bean class, optionally customizing its * bean definition metadata (typically declared as a lambda expression). * @param beanClass the class of the bean (resolving a public constructor * to be autowired, possibly simply the default constructor) * @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 * @see #registerBean(String, Class, Supplier, BeanDefinitionCustomizer...) */ public final <T> void registerBean(Class<T> beanClass, BeanDefinitionCustomizer... customizers) { registerBean(null, beanClass, null, customizers); }
Example #19
Source File: AnnotatedBeanDefinitionReader.java From spring-analysis-note with MIT License | 2 votes |
/** * 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 * (or {@code null} for generating a default bean name) * @param supplier a callback for creating an instance of the bean * (may be {@code null}) * @param customizers one or more callbacks for customizing the factory's * {@link BeanDefinition}, e.g. setting a lazy-init or primary flag * @since 5.2 */ public <T> void registerBean(Class<T> annotatedClass, @Nullable String name, @Nullable Supplier<T> supplier, BeanDefinitionCustomizer... customizers) { doRegisterBean(annotatedClass, name, null, supplier, customizers); }