List of usage examples for org.springframework.beans.factory.config ConfigurableListableBeanFactory getBeanNamesForType
String[] getBeanNamesForType(ResolvableType type);
From source file:net.tirasa.blog.ilgrosso.dynamicspringtransactional.TransactionInterceptorReplacer.java
@Override public void postProcessBeanFactory(final ConfigurableListableBeanFactory factory) throws BeansException { String[] names = factory.getBeanNamesForType(TransactionInterceptor.class); for (String name : names) { BeanDefinition bd = factory.getBeanDefinition(name); bd.setBeanClassName(DynamicTransactionInterceptor.class.getName()); }//from ww w . ja v a2 s . co m }
From source file:io.github.hzpz.spring.boot.autoconfigure.mongeez.DoNotExecuteMongeezPostProcessor.java
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] mongeezBeanNames = beanFactory.getBeanNamesForType(Mongeez.class); Assert.state(mongeezBeanNames.length == 1); BeanDefinition beanDefinition = beanFactory.getBeanDefinition(mongeezBeanNames[0]); Assert.state(beanDefinition instanceof RootBeanDefinition); ((RootBeanDefinition) beanDefinition).setInitMethodName(null); }
From source file:org.jacp.project.processor.StatelessScopedPostProcessor.java
public void postProcessBeanFactory(final ConfigurableListableBeanFactory factory) throws BeansException { final String[] stateless = factory.getBeanNamesForType(AStatelessCallbackComponent.class); for (final String beanName : stateless) { final BeanDefinition beanDefinition = factory.getBeanDefinition(beanName); beanDefinition.setScope("prototype"); }//from ww w . j a v a 2 s . c o m }
From source file:org.jacpfx.spring.processor.StatelessScopedPostProcessor.java
@Override public void postProcessBeanFactory(final ConfigurableListableBeanFactory factory) throws BeansException { final String[] stateless = factory.getBeanNamesForType(CallbackComponent.class); for (final String beanName : stateless) { final BeanDefinition beanDefinition = factory.getBeanDefinition(beanName); final String className = beanDefinition.getBeanClassName(); try {//from w ww . j av a 2s . co m Class<?> clazz = Class.forName(className); if (clazz.isAnnotationPresent(Stateless.class)) beanDefinition.setScope("prototype"); } catch (ClassNotFoundException e) { e.printStackTrace(); } } }
From source file:org.jdal.mock.EasyMockReplacer.java
/** * Replace Bean definition with a EasyMock Proxy * @param clazz clazz to replace// w w w. j av a 2 s.c o m * @param factory factory to replace on */ private void replaceBean(Class<?> clazz, ConfigurableListableBeanFactory factory) { Object mock = EasyMock.createMock(clazz); String[] names = factory.getBeanNamesForType(clazz); for (String name : names) { log.info("Registering bean " + name + " with mock " + clazz.getName()); factory.registerSingleton(name, mock); } }
From source file:com.bt.aloha.spring.BeanFactoryPostProcessorBase.java
protected void injectBeanIfDefined(ConfigurableListableBeanFactory beanFactory, String targetBeanName, String propertyName, Class<?> beanClassToInject) { String[] beanNamesForInjection = beanFactory.getBeanNamesForType(beanClassToInject); if (beanNamesForInjection != null && beanNamesForInjection.length > 0) { log.debug(String.format("Injecting bean %s into property %s of bean %s", beanClassToInject.getName(), propertyName, targetBeanName)); if (beanNamesForInjection.length > 1) log.debug(String.format("Multiple beans of type %s found, injecting only the first one into %s", beanClassToInject.getName(), targetBeanName)); PropertyValue propertyValue = new PropertyValue(propertyName, new RuntimeBeanReference(beanNamesForInjection[0])); BeanDefinition beanDefinition = beanFactory.getBeanDefinition(targetBeanName); beanDefinition.getPropertyValues().addPropertyValue(propertyValue); } else/* w w w. ja v a 2 s . c om*/ log.info(String.format("Property %s not set for bean %s", propertyName, targetBeanName)); }
From source file:org.bytesoft.bytetcc.supports.zk.TransactionCuratorClient.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanNameArray = beanFactory .getBeanNamesForType(org.bytesoft.bytetcc.supports.zk.TransactionCuratorClient.class); if (beanNameArray.length != 1) { throw new FatalBeanException("Multiple TransactionCuratorClient instance exists!"); }/* w ww. j a v a 2s . c o m*/ BeanDefinition beanDef = beanFactory.getBeanDefinition(beanNameArray[0]); MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue pv = mpv.getPropertyValue(KEY_FIELD_ZOOKEEPER_ADDRESS); if (pv == null || pv.getValue() == null || StringUtils.isBlank(String.valueOf(pv.getValue()))) { this.initZookeeperAddressIfNecessary(beanFactory); } }
From source file:net.nan21.dnet.core.presenter.descriptor.DsDefinitions.java
/** * Get the definitions for all data-sources available in the given context. *///from w ww. j a v a2 s . com @Override public Collection<IDsDefinition> getDsDefinitions() throws Exception { Collection<IDsDefinition> result = new ArrayList<IDsDefinition>(); ConfigurableListableBeanFactory factory = (ConfigurableListableBeanFactory) beanFactory; String[] names = factory.getBeanNamesForType(IDsBaseService.class); for (int i = 0; i < names.length; i++) { String name = names[i]; DsDefinition definition = createDefinition(name, factory); result.add(definition); } names = factory.getBeanNamesForType(IAsgnService.class); for (int i = 0; i < names.length; i++) { String name = names[i]; DsDefinition definition = createDefinition(name, factory); definition.setAsgn(true); result.add(definition); } return result; }
From source file:com.gzj.tulip.jade.context.spring.JadeBeanFactoryPostProcessor.java
public String getCacheProviderName(ConfigurableListableBeanFactory beanFactory) { if (cacheProviderName == null) { String[] names = beanFactory.getBeanNamesForType(CacheProvider.class); if (names.length == 0) { cacheProviderName = "none"; } else if (names.length == 1) { cacheProviderName = names[0]; } else {/*w w w .j a v a 2 s . c o m*/ String topPriority = "jade.cacheProvider"; if (ArrayUtils.contains(names, topPriority)) { cacheProviderName = topPriority; } else { throw new IllegalStateException( "required not more than 1 CacheProvider, but found " + names.length); } } } return "none".equals(cacheProviderName) ? null : cacheProviderName; }