org.springframework.beans.factory.config.BeanPostProcessor Java Examples
The following examples show how to use
org.springframework.beans.factory.config.BeanPostProcessor.
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: EmbeddedCassandraContextCustomizer.java From embedded-cassandra with Apache License 2.0 | 6 votes |
@Override public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) { BeanDefinitionRegistry registry = getRegistry(context); EmbeddedCassandra annotation = this.annotation; Resource[] resources = getResources(annotation, context); Charset charset = Charset.forName(annotation.encoding()); CqlDataSet dataSet = CqlDataSet.ofResources(charset, resources); registerCassandraBeanDefinition(annotation.exposeProperties(), context, registry); registerCassandraConnectionBeanDefinition(context, registry); registerCassandraInitializerBeanDefinition(dataSet, context, registry); context.getBeanFactory().addBeanPostProcessor(new BeanPostProcessor() { private final AtomicBoolean initialized = new AtomicBoolean(); @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof Cassandra && this.initialized.compareAndSet(false, true)) { context.getBean(CassandraInitializer.class); } return bean; } }); }
Example #2
Source File: AbstractBeanFactoryBasedTargetSourceCreator.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Build an internal BeanFactory for resolving target beans. * @param containingFactory the containing BeanFactory that originally defines the beans * @return an independent internal BeanFactory to hold copies of some target beans */ protected DefaultListableBeanFactory buildInternalBeanFactory(ConfigurableBeanFactory containingFactory) { // Set parent so that references (up container hierarchies) are correctly resolved. DefaultListableBeanFactory internalBeanFactory = new DefaultListableBeanFactory(containingFactory); // Required so that all BeanPostProcessors, Scopes, etc become available. internalBeanFactory.copyConfigurationFrom(containingFactory); // Filter out BeanPostProcessors that are part of the AOP infrastructure, // since those are only meant to apply to beans defined in the original factory. for (Iterator<BeanPostProcessor> it = internalBeanFactory.getBeanPostProcessors().iterator(); it.hasNext();) { if (it.next() instanceof AopInfrastructureBean) { it.remove(); } } return internalBeanFactory; }
Example #3
Source File: DisposableBeanAdapter.java From spring-analysis-note with MIT License | 6 votes |
/** * Search for all DestructionAwareBeanPostProcessors in the List. * @param processors the List to search * @return the filtered List of DestructionAwareBeanPostProcessors */ @Nullable private List<DestructionAwareBeanPostProcessor> filterPostProcessors(List<BeanPostProcessor> processors, Object bean) { List<DestructionAwareBeanPostProcessor> filteredPostProcessors = null; if (!CollectionUtils.isEmpty(processors)) { filteredPostProcessors = new ArrayList<>(processors.size()); for (BeanPostProcessor processor : processors) { if (processor instanceof DestructionAwareBeanPostProcessor) { DestructionAwareBeanPostProcessor dabpp = (DestructionAwareBeanPostProcessor) processor; if (dabpp.requiresDestruction(bean)) { filteredPostProcessors.add(dabpp); } } } } return filteredPostProcessors; }
Example #4
Source File: AbstractAutowireCapableBeanFactory.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Apply MergedBeanDefinitionPostProcessors to the specified bean definition, * invoking their {@code postProcessMergedBeanDefinition} methods. * @param mbd the merged bean definition for the bean * @param beanType the actual type of the managed bean instance * @param beanName the name of the bean * @throws BeansException if any post-processing failed * @see MergedBeanDefinitionPostProcessor#postProcessMergedBeanDefinition */ protected void applyMergedBeanDefinitionPostProcessors(RootBeanDefinition mbd, Class<?> beanType, String beanName) throws BeansException { try { for (BeanPostProcessor bp : getBeanPostProcessors()) { if (bp instanceof MergedBeanDefinitionPostProcessor) { MergedBeanDefinitionPostProcessor bdp = (MergedBeanDefinitionPostProcessor) bp; bdp.postProcessMergedBeanDefinition(mbd, beanType, beanName); } } } catch (Exception ex) { throw new BeanCreationException(mbd.getResourceDescription(), beanName, "Post-processing failed of bean type [" + beanType + "] failed", ex); } }
Example #5
Source File: LocatorsConfigurationIntegrationTests.java From spring-boot-data-geode with Apache License 2.0 | 6 votes |
@Bean BeanPostProcessor locatorFactoryBeanPostProcessor() { return new BeanPostProcessor() { @Nullable @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof LocatorFactoryBean) { return new TestLocatorFactoryBean((LocatorFactoryBean) bean); } return bean; } }; }
Example #6
Source File: ClusterNotAvailableConfiguration.java From spring-boot-data-geode with Apache License 2.0 | 6 votes |
@Bean BeanPostProcessor localClientRegionBeanPostProcessor(Environment environment) { return new BeanPostProcessor() { @Nullable @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (isClientRegion(bean)) { configureAsLocalClientRegion(environment, bean); } return bean; } }; }
Example #7
Source File: AbstractAutowireCapableBeanFactory.java From spring-analysis-note with MIT License | 6 votes |
@Override @Nullable protected Class<?> predictBeanType(String beanName, RootBeanDefinition mbd, Class<?>... typesToMatch) { Class<?> targetType = determineTargetType(beanName, mbd, typesToMatch); // Apply SmartInstantiationAwareBeanPostProcessors to predict the // eventual type after a before-instantiation shortcut. if (targetType != null && !mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) { for (BeanPostProcessor bp : getBeanPostProcessors()) { if (bp instanceof SmartInstantiationAwareBeanPostProcessor) { SmartInstantiationAwareBeanPostProcessor ibp = (SmartInstantiationAwareBeanPostProcessor) bp; Class<?> predicted = ibp.predictBeanType(targetType, beanName); if (predicted != null && (typesToMatch.length != 1 || FactoryBean.class != typesToMatch[0] || FactoryBean.class.isAssignableFrom(predicted))) { return predicted; } } } } return targetType; }
Example #8
Source File: AbstractAutowireCapableBeanFactory.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Determine candidate constructors to use for the given bean, checking all registered * {@link SmartInstantiationAwareBeanPostProcessor SmartInstantiationAwareBeanPostProcessors}. * @param beanClass the raw class of the bean * @param beanName the name of the bean * @return the candidate constructors, or {@code null} if none specified * @throws org.springframework.beans.BeansException in case of errors * @see org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor#determineCandidateConstructors */ protected Constructor<?>[] determineConstructorsFromBeanPostProcessors(Class<?> beanClass, String beanName) throws BeansException { if (beanClass != null && hasInstantiationAwareBeanPostProcessors()) { for (BeanPostProcessor bp : getBeanPostProcessors()) { if (bp instanceof SmartInstantiationAwareBeanPostProcessor) { SmartInstantiationAwareBeanPostProcessor ibp = (SmartInstantiationAwareBeanPostProcessor) bp; Constructor<?>[] ctors = ibp.determineCandidateConstructors(beanClass, beanName); if (ctors != null) { return ctors; } } } } return null; }
Example #9
Source File: AbstractAutowireCapableBeanFactory.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Obtain a reference for early access to the specified bean, * typically for the purpose of resolving a circular reference. * @param beanName the name of the bean (for error handling purposes) * @param mbd the merged bean definition for the bean * @param bean the raw bean instance * @return the object to expose as bean reference */ protected Object getEarlyBeanReference(String beanName, RootBeanDefinition mbd, Object bean) { Object exposedObject = bean; if (bean != null && !mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) { for (BeanPostProcessor bp : getBeanPostProcessors()) { if (bp instanceof SmartInstantiationAwareBeanPostProcessor) { SmartInstantiationAwareBeanPostProcessor ibp = (SmartInstantiationAwareBeanPostProcessor) bp; exposedObject = ibp.getEarlyBeanReference(exposedObject, beanName); if (exposedObject == null) { return null; } } } } return exposedObject; }
Example #10
Source File: ScriptFactoryPostProcessor.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public void setBeanFactory(BeanFactory beanFactory) { if (!(beanFactory instanceof ConfigurableBeanFactory)) { throw new IllegalStateException("ScriptFactoryPostProcessor doesn't work with a BeanFactory " + "which does not implement ConfigurableBeanFactory: " + beanFactory.getClass()); } this.beanFactory = (ConfigurableBeanFactory) beanFactory; // Required so that references (up container hierarchies) are correctly resolved. this.scriptBeanFactory.setParentBeanFactory(this.beanFactory); // Required so that all BeanPostProcessors, Scopes, etc become available. this.scriptBeanFactory.copyConfigurationFrom(this.beanFactory); // Filter out BeanPostProcessors that are part of the AOP infrastructure, // since those are only meant to apply to beans defined in the original factory. for (Iterator<BeanPostProcessor> it = this.scriptBeanFactory.getBeanPostProcessors().iterator(); it.hasNext();) { if (it.next() instanceof AopInfrastructureBean) { it.remove(); } } }
Example #11
Source File: DisposableBeanAdapter.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Check whether the given bean has destruction-aware post-processors applying to it. * @param bean the bean instance * @param postProcessors the post-processor candidates */ public static boolean hasApplicableProcessors(Object bean, List<BeanPostProcessor> postProcessors) { if (!CollectionUtils.isEmpty(postProcessors)) { for (BeanPostProcessor processor : postProcessors) { if (processor instanceof DestructionAwareBeanPostProcessor) { DestructionAwareBeanPostProcessor dabpp = (DestructionAwareBeanPostProcessor) processor; try { if (dabpp.requiresDestruction(bean)) { return true; } } catch (AbstractMethodError err) { // A pre-4.3 third-party DestructionAwareBeanPostProcessor... // As of 5.0, we can let requiresDestruction be a Java 8 default method which returns true. return true; } } } } return false; }
Example #12
Source File: DisposableBeanAdapter.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Search for all DestructionAwareBeanPostProcessors in the List. * @param processors the List to search * @return the filtered List of DestructionAwareBeanPostProcessors */ private List<DestructionAwareBeanPostProcessor> filterPostProcessors(List<BeanPostProcessor> processors, Object bean) { List<DestructionAwareBeanPostProcessor> filteredPostProcessors = null; if (!CollectionUtils.isEmpty(processors)) { filteredPostProcessors = new ArrayList<DestructionAwareBeanPostProcessor>(processors.size()); for (BeanPostProcessor processor : processors) { if (processor instanceof DestructionAwareBeanPostProcessor) { DestructionAwareBeanPostProcessor dabpp = (DestructionAwareBeanPostProcessor) processor; try { if (dabpp.requiresDestruction(bean)) { filteredPostProcessors.add(dabpp); } } catch (AbstractMethodError err) { // A pre-4.3 third-party DestructionAwareBeanPostProcessor... // As of 5.0, we can let requiresDestruction be a Java 8 default method which returns true. filteredPostProcessors.add(dabpp); } } } } return filteredPostProcessors; }
Example #13
Source File: AbstractAutowireCapableBeanFactory.java From spring-analysis-note with MIT License | 6 votes |
/** * Determine candidate constructors to use for the given bean, checking all registered * {@link SmartInstantiationAwareBeanPostProcessor SmartInstantiationAwareBeanPostProcessors}. * @param beanClass the raw class of the bean * @param beanName the name of the bean * @return the candidate constructors, or {@code null} if none specified * @throws org.springframework.beans.BeansException in case of errors * @see org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor#determineCandidateConstructors */ @Nullable protected Constructor<?>[] determineConstructorsFromBeanPostProcessors(@Nullable Class<?> beanClass, String beanName) throws BeansException { if (beanClass != null && hasInstantiationAwareBeanPostProcessors()) { for (BeanPostProcessor bp : getBeanPostProcessors()) { if (bp instanceof SmartInstantiationAwareBeanPostProcessor) { SmartInstantiationAwareBeanPostProcessor ibp = (SmartInstantiationAwareBeanPostProcessor) bp; Constructor<?>[] ctors = ibp.determineCandidateConstructors(beanClass, beanName); if (ctors != null) { return ctors; } } } } return null; }
Example #14
Source File: DisposableBeanAdapter.java From java-technology-stack with MIT License | 6 votes |
/** * Search for all DestructionAwareBeanPostProcessors in the List. * @param processors the List to search * @return the filtered List of DestructionAwareBeanPostProcessors */ @Nullable private List<DestructionAwareBeanPostProcessor> filterPostProcessors(List<BeanPostProcessor> processors, Object bean) { List<DestructionAwareBeanPostProcessor> filteredPostProcessors = null; if (!CollectionUtils.isEmpty(processors)) { filteredPostProcessors = new ArrayList<>(processors.size()); for (BeanPostProcessor processor : processors) { if (processor instanceof DestructionAwareBeanPostProcessor) { DestructionAwareBeanPostProcessor dabpp = (DestructionAwareBeanPostProcessor) processor; if (dabpp.requiresDestruction(bean)) { filteredPostProcessors.add(dabpp); } } } } return filteredPostProcessors; }
Example #15
Source File: ScriptFactoryPostProcessor.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public void setBeanFactory(BeanFactory beanFactory) { if (!(beanFactory instanceof ConfigurableBeanFactory)) { throw new IllegalStateException("ScriptFactoryPostProcessor doesn't work with " + "non-ConfigurableBeanFactory: " + beanFactory.getClass()); } this.beanFactory = (ConfigurableBeanFactory) beanFactory; // Required so that references (up container hierarchies) are correctly resolved. this.scriptBeanFactory.setParentBeanFactory(this.beanFactory); // Required so that all BeanPostProcessors, Scopes, etc become available. this.scriptBeanFactory.copyConfigurationFrom(this.beanFactory); // Filter out BeanPostProcessors that are part of the AOP infrastructure, // since those are only meant to apply to beans defined in the original factory. for (Iterator<BeanPostProcessor> it = this.scriptBeanFactory.getBeanPostProcessors().iterator(); it.hasNext();) { if (it.next() instanceof AopInfrastructureBean) { it.remove(); } } }
Example #16
Source File: AbstractAutowireCapableBeanFactory.java From java-technology-stack with MIT License | 6 votes |
@Override @Nullable protected Class<?> predictBeanType(String beanName, RootBeanDefinition mbd, Class<?>... typesToMatch) { Class<?> targetType = determineTargetType(beanName, mbd, typesToMatch); // Apply SmartInstantiationAwareBeanPostProcessors to predict the // eventual type after a before-instantiation shortcut. if (targetType != null && !mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) { for (BeanPostProcessor bp : getBeanPostProcessors()) { if (bp instanceof SmartInstantiationAwareBeanPostProcessor) { SmartInstantiationAwareBeanPostProcessor ibp = (SmartInstantiationAwareBeanPostProcessor) bp; Class<?> predicted = ibp.predictBeanType(targetType, beanName); if (predicted != null && (typesToMatch.length != 1 || FactoryBean.class != typesToMatch[0] || FactoryBean.class.isAssignableFrom(predicted))) { return predicted; } } } } return targetType; }
Example #17
Source File: AbstractAutowireCapableBeanFactory.java From lams with GNU General Public License v2.0 | 6 votes |
@Override protected Class<?> predictBeanType(String beanName, RootBeanDefinition mbd, Class<?>... typesToMatch) { Class<?> targetType = determineTargetType(beanName, mbd, typesToMatch); // Apply SmartInstantiationAwareBeanPostProcessors to predict the // eventual type after a before-instantiation shortcut. if (targetType != null && !mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) { for (BeanPostProcessor bp : getBeanPostProcessors()) { if (bp instanceof SmartInstantiationAwareBeanPostProcessor) { SmartInstantiationAwareBeanPostProcessor ibp = (SmartInstantiationAwareBeanPostProcessor) bp; Class<?> predicted = ibp.predictBeanType(targetType, beanName); if (predicted != null && (typesToMatch.length != 1 || FactoryBean.class != typesToMatch[0] || FactoryBean.class.isAssignableFrom(predicted))) { return predicted; } } } } return targetType; }
Example #18
Source File: NettyRpcClientBeanDefinitionRegistrar.java From spring-boot-protocol with Apache License 2.0 | 6 votes |
@Override public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) { GenericBeanDefinition beanPostProcessorDefinition = new GenericBeanDefinition(); beanPostProcessorDefinition.setInstanceSupplier(()->this); beanPostProcessorDefinition.setBeanClass(BeanPostProcessor.class); registry.registerBeanDefinition("NettyRpcClientBeanPostProcessor",beanPostProcessorDefinition); ClassPathScanningCandidateComponentProvider scanner = getScanner(); scanner.setResourceLoader(resourceLoader); scanner.addIncludeFilter(new AnnotationTypeFilter(NettyRpcClient.class)); Map<String, Object> enableNettyRpcClientsAttributes = metadata.getAnnotationAttributes(enableNettyRpcClientsCanonicalName); for (String basePackage : getBasePackages(metadata,enableNettyRpcClientsAttributes)) { for (BeanDefinition candidateComponent : scanner.findCandidateComponents(basePackage)) { if (!(candidateComponent instanceof AnnotatedBeanDefinition)) { continue; } AnnotatedBeanDefinition beanDefinition = (AnnotatedBeanDefinition) candidateComponent; if(!beanDefinition.getMetadata().isInterface()) { throw new IllegalArgumentException("@NettyRpcClient can only be specified on an interface"); } registerNettyRpcClient(beanDefinition,registry); } } }
Example #19
Source File: AbstractAutowireCapableBeanFactory.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName) throws BeansException { Object result = existingBean; for (BeanPostProcessor beanProcessor : getBeanPostProcessors()) { result = beanProcessor.postProcessAfterInitialization(result, beanName); if (result == null) { return result; } } return result; }
Example #20
Source File: AbstractAutowireCapableBeanFactory.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Apply MergedBeanDefinitionPostProcessors to the specified bean definition, * invoking their {@code postProcessMergedBeanDefinition} methods. * @param mbd the merged bean definition for the bean * @param beanType the actual type of the managed bean instance * @param beanName the name of the bean * @see MergedBeanDefinitionPostProcessor#postProcessMergedBeanDefinition */ protected void applyMergedBeanDefinitionPostProcessors(RootBeanDefinition mbd, Class<?> beanType, String beanName) { for (BeanPostProcessor bp : getBeanPostProcessors()) { if (bp instanceof MergedBeanDefinitionPostProcessor) { MergedBeanDefinitionPostProcessor bdp = (MergedBeanDefinitionPostProcessor) bp; bdp.postProcessMergedBeanDefinition(mbd, beanType, beanName); } } }
Example #21
Source File: PostProcessorRegistrationDelegate.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public Object postProcessAfterInitialization(Object bean, String beanName) { if (bean != null && !(bean instanceof BeanPostProcessor) && !isInfrastructureBean(beanName) && this.beanFactory.getBeanPostProcessorCount() < this.beanPostProcessorTargetCount) { if (logger.isInfoEnabled()) { logger.info("Bean '" + beanName + "' of type [" + bean.getClass().getName() + "] is not eligible for getting processed by all BeanPostProcessors " + "(for example: not eligible for auto-proxying)"); } } return bean; }
Example #22
Source File: PostProcessorRegistrationDelegate.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Register the given BeanPostProcessor beans. */ private static void registerBeanPostProcessors( ConfigurableListableBeanFactory beanFactory, List<BeanPostProcessor> postProcessors) { for (BeanPostProcessor postProcessor : postProcessors) { beanFactory.addBeanPostProcessor(postProcessor); } }
Example #23
Source File: DisposableBeanAdapter.java From blog_demos with Apache License 2.0 | 5 votes |
/** * Search for all DestructionAwareBeanPostProcessors in the List. * @param postProcessors the List to search * @return the filtered List of DestructionAwareBeanPostProcessors */ private List<DestructionAwareBeanPostProcessor> filterPostProcessors(List<BeanPostProcessor> postProcessors) { List<DestructionAwareBeanPostProcessor> filteredPostProcessors = null; if (postProcessors != null && !postProcessors.isEmpty()) { filteredPostProcessors = new ArrayList<DestructionAwareBeanPostProcessor>(postProcessors.size()); for (BeanPostProcessor postProcessor : postProcessors) { if (postProcessor instanceof DestructionAwareBeanPostProcessor) { filteredPostProcessors.add((DestructionAwareBeanPostProcessor) postProcessor); } } } return filteredPostProcessors; }
Example #24
Source File: AbstractBeanFactory.java From blog_demos with Apache License 2.0 | 5 votes |
@Override public void addBeanPostProcessor(BeanPostProcessor beanPostProcessor) { Assert.notNull(beanPostProcessor, "BeanPostProcessor must not be null"); this.beanPostProcessors.remove(beanPostProcessor); this.beanPostProcessors.add(beanPostProcessor); if (beanPostProcessor instanceof InstantiationAwareBeanPostProcessor) { this.hasInstantiationAwareBeanPostProcessors = true; } if (beanPostProcessor instanceof DestructionAwareBeanPostProcessor) { this.hasDestructionAwareBeanPostProcessors = true; } }
Example #25
Source File: AbstractAirsonicRestApiJukeboxIntTest.java From airsonic with GNU General Public License v3.0 | 5 votes |
@Bean public BeanPostProcessor convertToSpy() { return new BeanPostProcessor() { @Override public Object postProcessAfterInitialization(Object bean, String beanName) { if (bean instanceof PlayerDaoPlayQueueFactory) { PlayerDaoPlayQueueFactory temp = (PlayerDaoPlayQueueFactory) spy(bean); doReturn(spy(temp.createPlayQueue())).when(temp).createPlayQueue(); bean = temp; } return bean; } }; }
Example #26
Source File: GithubConfiguration.java From spring-cloud-release-tools with Apache License 2.0 | 5 votes |
@Bean BeanPostProcessor cachingGithubBeanPostProcessor() { return new BeanPostProcessor() { @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof RtGithub) { return new CachingGithub((Github) bean); } return bean; } }; }
Example #27
Source File: DisposableBeanAdapter.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Create a new DisposableBeanAdapter for the given bean. * @param bean the bean instance (never {@code null}) * @param beanName the name of the bean * @param beanDefinition the merged bean definition * @param postProcessors the List of BeanPostProcessors * (potentially DestructionAwareBeanPostProcessor), if any */ public DisposableBeanAdapter(Object bean, String beanName, RootBeanDefinition beanDefinition, List<BeanPostProcessor> postProcessors, AccessControlContext acc) { Assert.notNull(bean, "Disposable bean must not be null"); this.bean = bean; this.beanName = beanName; this.invokeDisposableBean = (this.bean instanceof DisposableBean && !beanDefinition.isExternallyManagedDestroyMethod("destroy")); this.nonPublicAccessAllowed = beanDefinition.isNonPublicAccessAllowed(); this.acc = acc; String destroyMethodName = inferDestroyMethodIfNecessary(bean, beanDefinition); if (destroyMethodName != null && !(this.invokeDisposableBean && "destroy".equals(destroyMethodName)) && !beanDefinition.isExternallyManagedDestroyMethod(destroyMethodName)) { this.destroyMethodName = destroyMethodName; this.destroyMethod = determineDestroyMethod(); if (this.destroyMethod == null) { if (beanDefinition.isEnforceDestroyMethod()) { throw new BeanDefinitionValidationException("Couldn't find a destroy method named '" + destroyMethodName + "' on bean with name '" + beanName + "'"); } } else { Class<?>[] paramTypes = this.destroyMethod.getParameterTypes(); if (paramTypes.length > 1) { throw new BeanDefinitionValidationException("Method '" + destroyMethodName + "' of bean '" + beanName + "' has more than one parameter - not supported as destroy method"); } else if (paramTypes.length == 1 && boolean.class != paramTypes[0]) { throw new BeanDefinitionValidationException("Method '" + destroyMethodName + "' of bean '" + beanName + "' has a non-boolean parameter - not supported as destroy method"); } } } this.beanPostProcessors = filterPostProcessors(postProcessors); }
Example #28
Source File: OpenTracingJdbcAutoConfiguration.java From opentracing-toolbox with MIT License | 5 votes |
@API(status = INTERNAL) @Bean @Role(BeanDefinition.ROLE_INFRASTRUCTURE) @ConditionalOnProperty(name = "opentracing.jdbc.enabled", havingValue = "true", matchIfMissing = true) public static BeanPostProcessor tracingDataSourceBeanPostProcessor(final BeanFactory beanFactory) { return new TracingProcessor(beanFactory); }
Example #29
Source File: AbstractAutowireCapableBeanFactory.java From blog_demos with Apache License 2.0 | 5 votes |
@Override public Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName) throws BeansException { Object result = existingBean; for (BeanPostProcessor beanProcessor : getBeanPostProcessors()) { result = beanProcessor.postProcessAfterInitialization(result, beanName); if (result == null) { return result; } } return result; }
Example #30
Source File: DisposableBeanAdapter.java From blog_demos with Apache License 2.0 | 5 votes |
/** * Create a new DisposableBeanAdapter for the given bean. * @param bean the bean instance (never {@code null}) * @param beanName the name of the bean * @param beanDefinition the merged bean definition * @param postProcessors the List of BeanPostProcessors * (potentially DestructionAwareBeanPostProcessor), if any */ public DisposableBeanAdapter(Object bean, String beanName, RootBeanDefinition beanDefinition, List<BeanPostProcessor> postProcessors, AccessControlContext acc) { Assert.notNull(bean, "Disposable bean must not be null"); this.bean = bean; this.beanName = beanName; this.invokeDisposableBean = (this.bean instanceof DisposableBean && !beanDefinition.isExternallyManagedDestroyMethod("destroy")); this.nonPublicAccessAllowed = beanDefinition.isNonPublicAccessAllowed(); this.acc = acc; String destroyMethodName = inferDestroyMethodIfNecessary(bean, beanDefinition); if (destroyMethodName != null && !(this.invokeDisposableBean && "destroy".equals(destroyMethodName)) && !beanDefinition.isExternallyManagedDestroyMethod(destroyMethodName)) { this.destroyMethodName = destroyMethodName; this.destroyMethod = determineDestroyMethod(); if (this.destroyMethod == null) { if (beanDefinition.isEnforceDestroyMethod()) { throw new BeanDefinitionValidationException("Couldn't find a destroy method named '" + destroyMethodName + "' on bean with name '" + beanName + "'"); } } else { Class<?>[] paramTypes = this.destroyMethod.getParameterTypes(); if (paramTypes.length > 1) { throw new BeanDefinitionValidationException("Method '" + destroyMethodName + "' of bean '" + beanName + "' has more than one parameter - not supported as destroy method"); } else if (paramTypes.length == 1 && !paramTypes[0].equals(boolean.class)) { throw new BeanDefinitionValidationException("Method '" + destroyMethodName + "' of bean '" + beanName + "' has a non-boolean parameter - not supported as destroy method"); } } } this.beanPostProcessors = filterPostProcessors(postProcessors); }