use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spock by spockframework.
the class SpringMockTestExecutionListener method beforeTestMethod.
@Override
public void beforeTestMethod(SpringTestContext testContext) throws Exception {
Object testInstance = testContext.getTestInstance();
if (!(testInstance instanceof Specification))
return;
Specification specification = (Specification) testInstance;
ScanScopedBeans scanScopedBeans = ReflectionUtil.getAnnotationRecursive(specification.getClass(), ScanScopedBeans.class);
Set<String> scopes = scanScopedBeans == null ? Collections.<String>emptySet() : new HashSet<>(Arrays.asList(scanScopedBeans.value()));
ApplicationContext applicationContext = testContext.getApplicationContext();
String[] mockBeanNames = applicationContext.getBeanDefinitionNames();
List<Object> mockedBeans = new ArrayList<>();
for (String beanName : mockBeanNames) {
BeanDefinition beanDefinition = ((BeanDefinitionRegistry) applicationContext).getBeanDefinition(beanName);
if (beanDefinition.isAbstract()) {
continue;
}
if (beanDefinition.isSingleton() || scanScopedBean(scanScopedBeans, scopes, beanDefinition)) {
Object bean = applicationContext.getBean(beanName);
if (mockUtil.isMock(bean)) {
mockUtil.attachMock(bean, specification);
mockedBeans.add(bean);
}
}
}
testContext.setAttribute(MOCKED_BEANS_LIST, mockedBeans);
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project leopard by tanhaichao.
the class LeopardBeanFactoryAware method registerBean.
// @PreDestroy
// public void destroy() {
// beanFactory = null;
// }
/**
* @desc 向spring容器注册bean
*
* @param beanName
*
* @param beanDefinition
*/
private static void registerBean(String beanName, BeanDefinition beanDefinition) {
BeanDefinitionRegistry beanDefinitonRegistry = (BeanDefinitionRegistry) beanFactory;
beanDefinitonRegistry.registerBeanDefinition(beanName, beanDefinition);
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project leopard by tanhaichao.
the class BeanDefinitionParserUtil method registerBeanDefinition.
// public static void registerBeanDefinition(String beanName, BeanDefinitionBuilder beanDefinitionBuilder) {
// registerBeanDefinition(LeopardBeanFactoryAware.getBeanFactory(), beanName, beanDefinitionBuilder);
// }
public static void registerBeanDefinition(BeanFactory beanFactory, String beanName, BeanDefinitionBuilder beanDefinitionBuilder) {
BeanDefinitionRegistry beanDefinitonRegistry = (BeanDefinitionRegistry) beanFactory;
BeanDefinition beanDefinition = beanDefinitionBuilder.getBeanDefinition();
beanDefinitonRegistry.registerBeanDefinition(beanName, beanDefinition);
beanFactory.getBean(beanName);
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-cloud-config by spring-cloud.
the class CompositeEnvironmentBeanFactoryPostProcessor method postProcessBeanFactory.
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
List<String> typePropertyList = CompositeUtils.getCompositeTypeList(environment);
for (int i = 0; i < typePropertyList.size(); i++) {
String type = typePropertyList.get(i);
String factoryName = CompositeUtils.getFactoryName(type, beanFactory);
Type[] factoryTypes = CompositeUtils.getEnvironmentRepositoryFactoryTypeParams(beanFactory, factoryName);
Class<? extends EnvironmentRepositoryProperties> propertiesClass = (Class<? extends EnvironmentRepositoryProperties>) factoryTypes[1];
EnvironmentRepositoryProperties properties = bindProperties(i, propertiesClass, environment);
AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(EnvironmentRepository.class).setFactoryMethodOnBean("build", factoryName).addConstructorArgValue(properties).getBeanDefinition();
String beanName = String.format("%s-env-repo%d", type, i);
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
registry.registerBeanDefinition(beanName, beanDefinition);
}
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project com.revolsys.open by revolsys.
the class ModuleImport method postProcessBeanFactory.
@Override
public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException {
if (beanFactory instanceof BeanDefinitionRegistry) {
final BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
postProcessBeanDefinitionRegistry(registry);
}
}
Aggregations