List of usage examples for org.springframework.beans.factory.support DefaultListableBeanFactory destroySingleton
@Override public void destroySingleton(String beanName)
From source file:com.helpinput.spring.registinerceptor.AbstractBeanRegistInterceptor.java
@Override public boolean afterRemove(Class<?> clz, String beanName, String scope, DefaultListableBeanFactory dlbf) { if (getCondition(clz)) { String refBeanName = beanName + beanNameSuffix; if (application_scope.equals(scope)) dlbf.destroyScopedBean(refBeanName); else if (singleton_scope.equals(scope)) dlbf.destroySingleton(refBeanName); dlbf.removeBeanDefinition(refBeanName); return true; }//w w w. j a v a 2 s .c o m return false; }
From source file:com.helpinput.spring.BeanRegister.java
public static boolean removeBean(DefaultListableBeanFactory dlbf, BeanInfo beanInfo, String beanName) { BeanDefinition bd = null;// w w w . j a v a 2s. co m if (!Utils.hasLength(beanName)) if (beanInfo != null) beanName = beanInfo.beanName; if (!Utils.hasLength(beanName)) return false; try { bd = dlbf.getBeanDefinition(beanName); if (bd != null) { //?bean? relativePath?, ?? // BeanRegister.runOnUnregisger(beanName, dlbf); String scope = bd.getScope(); /** * bean?application,singletonbeansession?view? flash? * requestbean, * session,view,flash,requestbeanapplicationbean * application,singletonbean * scopebeanbeanbean */ if (application_scope.equals(scope)) dlbf.destroyScopedBean(beanName); else if (singleton_scope.equals(scope)) dlbf.destroySingleton(beanName); dlbf.removeBeanDefinition(beanName); if (beanInfo != null && beanInfo.beanClass != null && PropertyEditor.class.isAssignableFrom(beanInfo.beanClass)) { ContextHolder.refreshers.remover(beanName); } List<BeanRegistInterceptor> interceptors = ContextHolder.beanRegistIntercpterHolder.getList(); if (Utils.hasLength(interceptors)) { for (BeanRegistInterceptor beanRegistInterceptor : interceptors) { if (beanRegistInterceptor.afterRemove(beanInfo.beanClass, beanName, scope, dlbf)) break; } } logRegist(Info.Removed, (String) bd.getAttribute(relativePath), beanInfo.beanName, scope); return true; } } catch (NoSuchBeanDefinitionException e) { //? BeanDefinition,????beanInfo, return true; } return false; }
From source file:org.sakaiproject.signup.tool.entityproviders.SignupEntityProducer.java
public void init() { if (log.isDebugEnabled()) log.debug("signup EP.init()"); try {// ww w. j av a 2 s . co m entityManager.registerEntityProducer(this, REFERENCE_ROOT); log.info("Registered kaltura entity producer as: " + REFERENCE_ROOT); // get the main sakai AC (it will be the parent of our AC) ApplicationContext sakaiAC = applicationContext.getParent(); if (sakaiAC != null && sakaiAC instanceof ConfigurableApplicationContext) { // only ConfigurableApplicationContext - or higher - can register singletons Object currentKEP = ComponentManager.get(SignupEntityProducer.class.getName()); // check if something is already registered if (currentKEP != null) { log.info("Found existing " + SignupEntityProducer.class.getName() + " in the ComponentManager: " + currentKEP); // attempt to unregister the existing bean (otherwise the register call will fail) try { // only DefaultListableBeanFactory - or higher - can unregister singletons DefaultListableBeanFactory dlbf = (DefaultListableBeanFactory) sakaiAC .getAutowireCapableBeanFactory(); dlbf.destroySingleton(SignupEntityProducer.class.getName()); log.info("Removed existing " + SignupEntityProducer.class.getName() + " from the ComponentManager"); } catch (Exception e) { log.warn("FAILED attempted removal of signup bean: " + e); } } // register this EP with the sakai AC ((ConfigurableApplicationContext) sakaiAC).getBeanFactory() .registerSingleton(SignupEntityProducer.class.getName(), this); } // now verify if we are good to go if (ComponentManager.get(SignupEntityProducer.class.getName()) != null) { log.info("Found " + SignupEntityProducer.class.getName() + " in the ComponentManager"); } else { log.warn("FAILED to insert and lookup " + SignupEntityProducer.class.getName() + " in the Sakai ComponentManager, archive imports for signup will not work"); } } catch (Exception ex) { log.warn("signup EP.init(): " + ex, ex); } this.copyFileProcessor = new CopyFileProcessor(getSakaiFacade(), getSignupMeetingService()); }
From source file:io.gravitee.gateway.services.apikeyscache.ApiKeysCacheService.java
@Override protected void doStart() throws Exception { if (enabled) { super.doStart(); LOGGER.info("Overriding API key repository implementation with cached API Key repository"); DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) ((ConfigurableApplicationContext) applicationContext .getParent()).getBeanFactory(); this.apiKeyRepository = beanFactory.getBean(ApiKeyRepository.class); LOGGER.debug("Current API key repository implementation is {}", apiKeyRepository.getClass().getName()); String[] beanNames = beanFactory.getBeanNamesForType(ApiKeyRepository.class); String oldBeanName = beanNames[0]; beanFactory.destroySingleton(oldBeanName); LOGGER.debug("Register API key repository implementation {}", ApiKeyRepositoryWrapper.class.getName()); beanFactory.registerSingleton(ApiKeyRepository.class.getName(), new ApiKeyRepositoryWrapper(this.apiKeyRepository, cache)); eventManager.subscribeForEvents(this, ReactorEvent.class); executorService = Executors.newScheduledThreadPool(threads, new ThreadFactory() { private int counter = 0; private String prefix = "apikeys-refresher"; @Override/* ww w. ja v a 2 s . com*/ public Thread newThread(Runnable r) { return new Thread(r, prefix + '-' + counter++); } }); } }
From source file:org.springframework.cloud.gcp.data.spanner.test.AbstractSpannerIntegrationTest.java
@After public void clean() { try {/*from ww w. j a v a 2 s . c om*/ // this is to reduce duplicated errors reported by surefire plugin if (setupFailed || initializeAttempts > 0) { initializeAttempts--; return; } this.spannerDatabaseAdminTemplate.executeDdlStrings(dropSchemaStatements(), false); LOGGER.debug("Integration database cleaned up!"); } finally { // we need to remove the extra bean created even if there is a failure at // startup DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) this.applicationContext .getAutowireCapableBeanFactory(); beanFactory.destroySingleton(TABLE_NAME_SUFFIX_BEAN_NAME); } }