本文整理汇总了Java中org.springframework.beans.factory.support.BeanDefinitionRegistry类的典型用法代码示例。如果您正苦于以下问题:Java BeanDefinitionRegistry类的具体用法?Java BeanDefinitionRegistry怎么用?Java BeanDefinitionRegistry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BeanDefinitionRegistry类属于org.springframework.beans.factory.support包,在下文中一共展示了BeanDefinitionRegistry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDataSourceBeanName
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入依赖的package包/类
/**
* Get the {@link DataSource} type bean name which corresponds to given data context id
* @param registry Bean registry
* @param beanFactory Bean factory
* @param dataContextId Optional data context id
* @return The DataSource bean name, or <code>null</code> if not found
*/
private static String getDataSourceBeanName(BeanDefinitionRegistry registry, BeanFactory beanFactory,
String dataContextId) {
// check unique DataSource if no data context id specified
if (dataContextId == null && beanFactory instanceof ListableBeanFactory) {
String[] dataSourceBeanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
(ListableBeanFactory) beanFactory, DataSource.class, false, false);
if (dataSourceBeanNames != null && dataSourceBeanNames.length == 1) {
return dataSourceBeanNames[0];
}
}
// check bean name using data context id
String dsBeanName = BeanRegistryUtils.buildBeanName(dataContextId,
EnableDataSource.DEFAULT_DATASOURCE_BEAN_NAME);
if (registry.containsBeanDefinition(dsBeanName) && beanFactory.isTypeMatch(dsBeanName, DataSource.class)) {
return dsBeanName;
}
return null;
}
示例2: registerBeanDefinitions
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
logger.debug("Searching for mappers annotated with @Mapper");
ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);
try {
if (this.resourceLoader != null) {
scanner.setResourceLoader(this.resourceLoader);
}
List<String> packages = AutoConfigurationPackages.get(this.beanFactory);
if (logger.isDebugEnabled()) {
for (String pkg : packages) {
logger.debug("Using auto-configuration base package '" + pkg + "'");
}
}
scanner.setAnnotationClass(Mapper.class);
scanner.registerFilters();
scanner.doScan(StringUtils.toStringArray(packages));
} catch (IllegalStateException ex) {
logger.debug("Could not determine auto-configuration package, automatic mapper scanning disabled." + ex);
}
}
示例3: registerBeanDefinitions
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
AnnotationAttributes attributes = AnnotationAttributes.fromMap(importingClassMetadata
.getAnnotationAttributes(EnableApolloConfig.class.getName()));
String[] namespaces = attributes.getStringArray("value");
int order = attributes.getNumber("order");
PropertySourcesProcessor.addNamespaces(Lists.newArrayList(namespaces), order);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesPlaceholderConfigurer.class.getName(),
PropertySourcesPlaceholderConfigurer.class);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesProcessor.class.getName(),
PropertySourcesProcessor.class);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, ApolloAnnotationProcessor.class.getName(),
ApolloAnnotationProcessor.class);
}
示例4: registerOrEscalateApcAsRequired
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入依赖的package包/类
private static BeanDefinition registerOrEscalateApcAsRequired(Class<?> cls, BeanDefinitionRegistry registry, Object source) {
Assert.notNull(registry, "BeanDefinitionRegistry must not be null");
if (registry.containsBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME)) {
BeanDefinition apcDefinition = registry.getBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME);
if (!cls.getName().equals(apcDefinition.getBeanClassName())) {
int currentPriority = findPriorityForClass(apcDefinition.getBeanClassName());
int requiredPriority = findPriorityForClass(cls);
if (currentPriority < requiredPriority) {
apcDefinition.setBeanClassName(cls.getName());
}
}
return null;
}
RootBeanDefinition beanDefinition = new RootBeanDefinition(cls);
beanDefinition.setSource(source);
beanDefinition.getPropertyValues().add("order", Ordered.HIGHEST_PRECEDENCE);
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
registry.registerBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME, beanDefinition);
return beanDefinition;
}
示例5: registerBeanDefinitions
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {
Map<String, Object> attributes = annotationMetadata.getAnnotationAttributes(EnableBeanContext.class.getName());
if (attributes == null) {
return;
}
boolean lookupByType = (boolean) attributes.get("lookupByType");
// check environment
if (environment.containsProperty(EnableBeanContext.LOOKUP_BY_TYPE_PROPERTY_NAME)) {
lookupByType = environment.getProperty(EnableBeanContext.LOOKUP_BY_TYPE_PROPERTY_NAME, Boolean.class);
}
// register post processor
if (!registry.containsBeanDefinition(BEAN_FACTORY_SCOPE_POST_PROCESSOR_NAME)) {
BeanDefinitionBuilder postProcessorBuilder = BeanDefinitionBuilder
.genericBeanDefinition(BeanFactoryScopePostProcessor.class).setDestroyMethodName("unregister")
.addPropertyValue("lookupByType", lookupByType).setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
registry.registerBeanDefinition(BEAN_FACTORY_SCOPE_POST_PROCESSOR_NAME,
postProcessorBuilder.getBeanDefinition());
}
}
示例6: registerBeanDefinitions
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata metadata,
BeanDefinitionRegistry registry) {
MultiValueMap<String, Object> attributes = metadata
.getAllAnnotationAttributes(
EnableConfigService.class.getName(), false);
Object[] type = attributes == null ? null
: (Object[]) attributes.getFirst("converters");
if (type == null || type.length == 0) {
return;
}
List<Class<?>> types = collectClasses(attributes.get("converters"));
// for (Class<?> type : types) {
// String name = type.getName();
// if (!registry.containsBeanDefinition(name)) {
// registerBeanDefinition(registry, type, name);
// }
// }
registerConverters(registry, types);
}
示例7: registerDependency
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入依赖的package包/类
public static void registerDependency(BeanDefinitionRegistry registry, String beanName, String[] propertyNames) {
if (ArrayUtils.isEmpty(propertyNames)) {
return;
}
String dependencyBeanName = beanName + ".dependency";
BeanDefinitionBuilder meta = BeanDefinitionBuilder.genericBeanDefinition(RefreshBeanDependencyFactoryBean.class);
meta.addPropertyValue("beanName", beanName);
meta.addPropertyValue("propertyNames", propertyNames);
registry.registerBeanDefinition(dependencyBeanName, meta.getBeanDefinition());
}
示例8: registerBeanDefinitionIfNotExists
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入依赖的package包/类
public static boolean registerBeanDefinitionIfNotExists(BeanDefinitionRegistry registry, String beanName,
Class<?> beanClass) {
if (registry.containsBeanDefinition(beanName)) {
return false;
}
String[] candidates = registry.getBeanDefinitionNames();
for (String candidate : candidates) {
BeanDefinition beanDefinition = registry.getBeanDefinition(candidate);
if (Objects.equals(beanDefinition.getBeanClassName(), beanClass.getName())) {
return false;
}
}
BeanDefinition annotationProcessor = BeanDefinitionBuilder.genericBeanDefinition(beanClass).getBeanDefinition();
registry.registerBeanDefinition(beanName, annotationProcessor);
return true;
}
示例9: postProcessBeanFactory
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入依赖的package包/类
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
throws BeansException {
if (annotationPackage == null || annotationPackage.length() == 0) {
return;
}
if (beanFactory instanceof BeanDefinitionRegistry) {
try {
// init scanner
Class<?> scannerClass = ReflectUtils.forName("org.springframework.context.annotation.ClassPathBeanDefinitionScanner");
Object scanner = scannerClass.getConstructor(new Class<?>[] {BeanDefinitionRegistry.class, boolean.class}).newInstance(new Object[] {(BeanDefinitionRegistry) beanFactory, true});
// add filter
Class<?> filterClass = ReflectUtils.forName("org.springframework.core.type.filter.AnnotationTypeFilter");
Object filter = filterClass.getConstructor(Class.class).newInstance(Service.class);
Method addIncludeFilter = scannerClass.getMethod("addIncludeFilter", ReflectUtils.forName("org.springframework.core.type.filter.TypeFilter"));
addIncludeFilter.invoke(scanner, filter);
// scan packages
String[] packages = Constants.COMMA_SPLIT_PATTERN.split(annotationPackage);
Method scan = scannerClass.getMethod("scan", new Class<?>[]{String[].class});
scan.invoke(scanner, new Object[] {packages});
} catch (Throwable e) {
// spring 2.0
}
}
}
示例10: registerBeanDefinitions
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
if (beanFactory instanceof ListableBeanFactory) {
String[] dataSourceBeanNames = ((ListableBeanFactory) beanFactory).getBeanNamesForType(DataSource.class,
false, true);
if (dataSourceBeanNames != null) {
for (String dataSourceBeanName : dataSourceBeanNames) {
BeanDefinition bd = registry.getBeanDefinition(dataSourceBeanName);
if (bd instanceof DataContextBoundBeanDefinition) {
DataSourceRegistrar.registerDataSourceTransactionManager(registry, dataSourceBeanName,
((DataContextBoundBeanDefinition) bd).getDataContextId().orElse(null),
PrimaryMode.AUTO);
}
}
}
}
}
开发者ID:holon-platform,项目名称:holon-jdbc,代码行数:22,代码来源:DataSourcesTransactionManagerAutoConfigurationRegistrar.java
示例11: registerBeans
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入依赖的package包/类
@Override
protected void registerBeans(InjectRpcClient annotation, ResolvableType targetType, BeanDefinitionRegistry registry) {
String tag = annotation.tag().isEmpty() ? "" : '#' + annotation.tag();
String name = RpcClientBean.class.getName() + tag + "-" + targetType.toString();
if (!registry.containsBeanDefinition(name)) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(RpcClientBean.class)
.setLazyInit(true)
.addPropertyValue("rpcInterface", targetType.getType().getTypeName());
if (!annotation.tag().isEmpty()) {
builder.addPropertyValue("tag", annotation.tag());
}
AbstractBeanDefinition def = builder.getBeanDefinition();
AutowireCandidateQualifier qualifier = new AutowireCandidateQualifier(annotation.annotationType());
if (!annotation.tag().isEmpty()) {
qualifier.setAttribute("tag", annotation.tag());
}
def.addQualifier(qualifier);
registry.registerBeanDefinition(name, def);
}
}
示例12: postProcessBeanDefinitionRegistry
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入依赖的package包/类
/**
* 第一次扫描<br/>
* 在Spring内部的Bean定义初始化后执行,这样是最高优先级的
*/
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
// 为了做兼容
DisconfCenterHostFilesStore.getInstance().addJustHostFileSet(fileList);
List<String> scanPackList = StringUtil.parseStringToStringList(scanPackage, SCAN_SPLIT_TOKEN);
// unique
Set<String> hs = new HashSet<String>();
hs.addAll(scanPackList);
scanPackList.clear();
scanPackList.addAll(hs);
// 进行扫描
DisconfMgrExt.getInstance().setApplicationContext(applicationContext);
DisconfMgrExt.getInstance().firstScan(scanPackList);
// register java bean
registerAspect(registry);
}
示例13: customizeContext
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入依赖的package包/类
@Override
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
Class<?> testClass = mergedConfig.getTestClass();
FlywayTest flywayAnnotation = AnnotatedElementUtils.findMergedAnnotation(testClass, FlywayTest.class);
BeanDefinitionRegistry registry = getBeanDefinitionRegistry(context);
RootBeanDefinition registrarDefinition = new RootBeanDefinition();
registrarDefinition.setBeanClass(PreloadableEmbeddedPostgresRegistrar.class);
registrarDefinition.getConstructorArgumentValues()
.addIndexedArgumentValue(0, databaseAnnotation);
registrarDefinition.getConstructorArgumentValues()
.addIndexedArgumentValue(1, flywayAnnotation);
registry.registerBeanDefinition("preloadableEmbeddedPostgresRegistrar", registrarDefinition);
}
开发者ID:zonkyio,项目名称:embedded-database-spring-test,代码行数:17,代码来源:EmbeddedPostgresContextCustomizerFactory.java
示例14: decorate
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入依赖的package包/类
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext)
{
Element element = (Element) node;
String type = element.getAttribute("type");
String className = element.getAttribute("class");
String javascriptClassName = element.getAttribute("javascript");
BeanDefinitionRegistry registry = parserContext.getRegistry();
ConverterConfig converterConfig = new ConverterConfig();
converterConfig.setType(type);
converterConfig.setJavascriptClassName(javascriptClassName);
parseConverterSettings(converterConfig, element);
lookupConverters(registry).put(className, converterConfig);
return definition;
}
示例15: postProcessBeanDefinitionRegistry
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入依赖的package包/类
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
/**
* 注册通用Dao
*/
registerBaseCommonDao(registry);
/**
* 注册代理类
*/
registerProxyHandler(registry);
/**
* 加载其他层接口
*/
ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry, annotation);
scanner.scan(StringUtils.tokenizeToStringArray(this.basePackage, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS));
}