本文整理匯總了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));
}