List of usage examples for org.springframework.beans.factory.support BeanDefinitionRegistry removeBeanDefinition
void removeBeanDefinition(String beanName) throws NoSuchBeanDefinitionException;
From source file:com.mmnaseri.dragonfly.runtime.assets.BeanDisposer.java
private void dispose(BeanDefinitionRegistry definitionRegistry, String disposable) { log.info("Disposing of bean " + disposable); definitionRegistry.removeBeanDefinition(disposable); }
From source file:com.mmnaseri.dragonfly.runtime.analysis.ApplicationDesignAdvisor.java
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; reportIssues(analyze());/*from w ww . j a v a 2 s.c om*/ final BeanDefinitionRegistry definitionRegistry = (BeanDefinitionRegistry) applicationContext .getAutowireCapableBeanFactory(); definitionRegistry.removeBeanDefinition(beanName); }
From source file:de.axelfaust.alfresco.hackathon.cmisserver.repo.beans.PatternBasedBeanRemovingFactoryPostProcessor.java
/** * {@inheritDoc}// w w w .j a v a2s . co m */ @Override public void postProcessBeanDefinitionRegistry(final BeanDefinitionRegistry registry) throws BeansException { for (final String beanName : registry.getBeanDefinitionNames()) { if (beanName.matches(this.beanNamePattern) && !this.excludeBeanNames.contains(beanName)) { registry.removeBeanDefinition(beanName); } } }
From source file:de.axelfaust.alfresco.hackathon.cmisserver.repo.beans.BeanDefinitionRemovingRegistryPostProcessor.java
@Override public void postProcessBeanDefinitionRegistry(final BeanDefinitionRegistry registry) throws BeansException { for (final String beanName : this.beanNames) { if (registry.containsBeanDefinition(beanName)) { LOGGER.info("Removing configured bean {}", beanName); registry.removeBeanDefinition(beanName); } else if (registry.isAlias(beanName)) { registry.removeAlias(beanName); } else {// w ww . ja va 2 s . c o m LOGGER.debug("Bean registry {} does not contain bean definition for {}", registry, beanName); } } }
From source file:com.fitbur.testify.di.spring.SpringServiceLocator.java
@Override public void removeService(ServiceDescriptor descriptor) { BeanDefinitionRegistry beanFactory = (BeanDefinitionRegistry) context; beanFactory.removeBeanDefinition(descriptor.getName()); }
From source file:com.fitbur.testify.di.spring.SpringServiceLocator.java
@Override public void removeService(String name) { BeanDefinitionRegistry beanFactory = (BeanDefinitionRegistry) context; beanFactory.removeBeanDefinition(name); }
From source file:de.acosix.alfresco.utility.common.spring.BeanDefinitionFromPropertiesPostProcessor.java
protected void processRenamesOrRemovals(final BeanDefinitionRegistry registry, final Set<Object> processedKeys) { final String effectivePropertyPrefix = this.propertyPrefix + DOT; this.propertiesSource.forEach((key, value) -> { if (!processedKeys.contains(key)) { final Pair<String, String> processableKeyValue = this.getProcessableKeyValue(key, value, effectivePropertyPrefix); if (processableKeyValue != null) { LOGGER.debug("[{}] Evaluating property key {}", this.beanName, key); final String beanDefinitionKey = processableKeyValue.getFirst(); final String resolvedValue = processableKeyValue.getSecond(); final int propertyFragmentIdx = beanDefinitionKey.indexOf(FRAGMENT_PROPERTY); if (propertyFragmentIdx == -1) { LOGGER.trace("[{}] Processing entry {} = {}", this.beanName, key, resolvedValue); if (beanDefinitionKey.contains(FRAGMENT_RENAME)) { final String beanName = beanDefinitionKey.substring(0, beanDefinitionKey.indexOf(FRAGMENT_RENAME)); final String targetBeanName = beanDefinitionKey.substring( beanDefinitionKey.indexOf(FRAGMENT_RENAME) + FRAGMENT_RENAME.length()); if (Boolean.parseBoolean(resolvedValue)) { if (registry.containsBeanDefinition(beanName)) { LOGGER.debug("[{}] Renaming bean {} to {}", this.beanName, beanName, targetBeanName); final BeanDefinition beanDefinition = registry.getBeanDefinition(beanName); registry.removeBeanDefinition(beanName); registry.registerBeanDefinition(targetBeanName, beanDefinition); } else { LOGGER.debug("[{}] Unable to rename bean {} to {} - bean has not been defined", this.beanName, beanName, targetBeanName); }/*from www. j a v a 2s. co m*/ } else { LOGGER.debug("[{}] Not renaming bean {} to {} due to non-true property value", this.beanName, beanName, targetBeanName); } processedKeys.add(key); } else if (beanDefinitionKey.endsWith(SUFFIX_REMOVE)) { final String beanName = beanDefinitionKey.substring(0, beanDefinitionKey.indexOf(SUFFIX_REMOVE)); if (Boolean.parseBoolean(resolvedValue)) { if (registry.containsBeanDefinition(beanName)) { LOGGER.debug("[{}] Removing bean {}", this.beanName, beanName); registry.removeBeanDefinition(beanName); } else { LOGGER.debug("[{}] Unable to remove bean {} - bean has not been defined", this.beanName, beanName); } } else { LOGGER.debug("[{}] Not removing bean {} due to non-true property value", this.beanName, beanName); } processedKeys.add(key); } else { LOGGER.trace("[{}] Setting unsupported by processRenamesOrRemovals: {} = {}", this.beanName, key, resolvedValue); } } else { final String beanName = beanDefinitionKey.substring(0, propertyFragmentIdx); final String propertyDefinitionKey = beanDefinitionKey .substring(propertyFragmentIdx + FRAGMENT_PROPERTY.length()); if (propertyDefinitionKey.endsWith(SUFFIX_REMOVE)) { final String propertyName = propertyDefinitionKey.substring(0, propertyDefinitionKey.indexOf(SUFFIX_REMOVE)); if (registry.containsBeanDefinition(beanName)) { final BeanDefinition beanDefinition = registry.getBeanDefinition(beanName); final MutablePropertyValues propertyValues = beanDefinition.getPropertyValues(); if (propertyValues.contains(propertyName)) { if (value instanceof String && Boolean.parseBoolean(resolvedValue)) { LOGGER.debug("[{}] Removing property {} from {}", this.beanName, propertyName, beanName); propertyValues.removePropertyValue(propertyName); } else { LOGGER.debug( "[{}] Not removing property {} from [} due to non-true property value", this.beanName, propertyName, beanName); } processedKeys.add(key); } else { LOGGER.trace( "[{}] Property {} not found in bean {} - key {} may refer to removal of values in collection-like property", this.beanName, propertyName, beanName, key); } } else { LOGGER.debug( "[{}] Unable to remove property {} from {} - bean has not been defined", this.beanName, propertyName, beanName); processedKeys.add(key); } } } } } }); }
From source file:org.springframework.cloud.function.context.config.KotlinLambdaToFunctionAutoConfiguration.java
/** * Will transform all discovered Kotlin's Function1 and Function0 lambdas to java * Supplier, Function and Consumer, retaining the original Kotlin type * characteristics. In other words the resulting bean could be cast to both java and * kotlin types (i.e., java Function<I,O> vs. kotlin Function1<I,O>) * @return the bean factory post processor *//*from w w w .j ava 2s. c o m*/ @Bean public BeanFactoryPostProcessor kotlinToFunctionTransformer() { return new BeanFactoryPostProcessor() { @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames(); for (String beanDefinitionName : beanDefinitionNames) { BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanDefinitionName); Object source = beanDefinition.getSource(); if (source instanceof MethodMetadata) { String returnTypeName = ((MethodMetadata) source).getReturnTypeName(); if (returnTypeName.startsWith("kotlin.jvm.functions.Function")) { FunctionType functionType = new FunctionType( FunctionContextUtils.findType(beanDefinitionName, beanFactory)); if (returnTypeName.equals("kotlin.jvm.functions.Function1")) { if (Unit.class.isAssignableFrom(functionType.getOutputType())) { KotlinLambdaToFunctionAutoConfiguration.this.logger .debug("Transforming Kotlin lambda " + beanDefinitionName + " to java Consumer"); this.register(beanDefinitionName, beanDefinition, KotlinConsumer.class, (BeanDefinitionRegistry) beanFactory); } else { KotlinLambdaToFunctionAutoConfiguration.this.logger .debug("Transforming Kotlin lambda " + beanDefinitionName + " to java Function"); this.register(beanDefinitionName, beanDefinition, KotlinFunction.class, (BeanDefinitionRegistry) beanFactory); } } else { KotlinLambdaToFunctionAutoConfiguration.this.logger.debug( "Transforming Kotlin lambda " + beanDefinitionName + " to java Supplier"); this.register(beanDefinitionName, beanDefinition, KotlinSupplier.class, (BeanDefinitionRegistry) beanFactory); } } } } } private void register(String originalName, BeanDefinition originalDefinition, Class<?> clazz, BeanDefinitionRegistry registry) { RootBeanDefinition cbd = new RootBeanDefinition(clazz); ConstructorArgumentValues ca = new ConstructorArgumentValues(); ca.addGenericArgumentValue(originalDefinition); cbd.setConstructorArgumentValues(ca); registry.removeBeanDefinition(originalName); registry.registerBeanDefinition(originalName, cbd); } }; }