本文整理汇总了Java中org.springframework.beans.factory.support.BeanDefinitionRegistry.getBeanDefinition方法的典型用法代码示例。如果您正苦于以下问题:Java BeanDefinitionRegistry.getBeanDefinition方法的具体用法?Java BeanDefinitionRegistry.getBeanDefinition怎么用?Java BeanDefinitionRegistry.getBeanDefinition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.beans.factory.support.BeanDefinitionRegistry
的用法示例。
在下文中一共展示了BeanDefinitionRegistry.getBeanDefinition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateServiceReferences
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
protected void validateServiceReferences(Element element, String serviceId, ParserContext parserContext) {
BeanDefinitionRegistry registry = parserContext.getRegistry();
String[] names = registry.getBeanDefinitionNames();
for (String name : names) {
BeanDefinition definition = registry.getBeanDefinition(name);
Collection<String> exporters =
(Collection<String>) definition.getAttribute(ParserUtils.REFERENCE_LISTENER_REF_ATTR);
if (exporters != null && exporters.contains(serviceId)) {
parserContext.getReaderContext()
.error(
"Service exporter '" + serviceId + "' cannot be used as a reference listener by '"
+ name + "'", element);
}
}
}
示例2: 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;
}
示例3: isBeanRegistered
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
/**
* Checks if a bean of given type and bound to given data context id is already registered
* @param beanFactory Bean factory
* @param registry Bean registry
* @param type Bean type to check
* @param dataContextId Data context id
* @param defaultBeanName Default bean name to check
* @return The registered bean name if found, <code>null</code> otherwise
*/
private static String isBeanRegistered(ListableBeanFactory beanFactory, BeanDefinitionRegistry registry,
Class<?> type, String dataContextId, String defaultBeanName) {
String[] beanNames = beanFactory.getBeanNamesForType(type);
if (beanNames != null && beanNames.length > 0) {
for (String beanName : beanNames) {
BeanDefinition bd = registry.getBeanDefinition(beanName);
if (bd instanceof DataContextBoundBeanDefinition) {
String did = ((DataContextBoundBeanDefinition) bd).getDataContextId().orElse(null);
if ((dataContextId == null && did == null)
|| (dataContextId != null && dataContextId.equals(did))) {
return beanName;
}
} else {
if (dataContextId == null) {
return beanName;
}
}
}
}
if (defaultBeanName != null && registry.containsBeanDefinition(defaultBeanName)) {
return defaultBeanName;
}
return null;
}
示例4: findParentDefinition
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
private BeanDefinition findParentDefinition(String parentName, BeanDefinitionRegistry registry)
{
if (registry != null)
{
if (registry.containsBeanDefinition(parentName))
{
return registry.getBeanDefinition(parentName);
}
else if (registry instanceof HierarchicalBeanFactory)
{
// Try to get parent definition from the parent BeanFactory. This could return null
BeanFactory parentBeanFactory = ((HierarchicalBeanFactory)registry).getParentBeanFactory();
return findParentDefinition(parentName, (BeanDefinitionRegistry)parentBeanFactory);
}
}
// we've exhausted all possibilities
return null;
}
示例5: 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
示例6: 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;
}
示例7: registerFactoryMethodForConfigBeans
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
/**
* 为@ConfigBean的bean注册它的Factory Method,通过静态Factory Method来创建@ConfigBean实例
*
* @param registry
*/
private void registerFactoryMethodForConfigBeans(BeanDefinitionRegistry registry) {
for (String beanName : registry.getBeanDefinitionNames()) {
BeanDefinition beanDefinition = registry.getBeanDefinition(beanName);
registerFactoryMethodForConfigBean(registry, beanName, beanDefinition);
}
}
示例8: getRefreshScopeBeans
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
/**
* 获取所有可刷新的beans
*
* @param registry
*/
private List<String> getRefreshScopeBeans(BeanDefinitionRegistry registry) {
List<String> beanNames = new ArrayList<>();
for (String beanName : registry.getBeanDefinitionNames()) {
BeanDefinition beanDefinition = registry.getBeanDefinition(beanName);
if (VersionRefreshScope.SCOPE_NAME.equalsIgnoreCase(beanDefinition.getScope())) {
beanNames.add(beanName);
}
}
return beanNames;
}
示例9: registerSpringConfiguratorIfNecessary
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
protected BeanDefinition registerSpringConfiguratorIfNecessary(BeanDefinitionRegistry registry)
{
if (!registry.containsBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID))
{
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(SpringConfigurator.class);
builder.addPropertyValue("creators", new ManagedMap());
builder.addPropertyValue("converters", new ManagedMap());
registry.registerBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID, builder.getBeanDefinition());
}
return registry.getBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID);
}
示例10: registerBeanDefinitions
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {
if (beanFactory instanceof ListableBeanFactory) {
// Get DataSource bean names
List<String> dataSourceBeanNames = BeanRegistryUtils.getBeanNames((ListableBeanFactory) beanFactory,
DataSource.class);
List<String> dataSourceFactoryBeanNames = BeanRegistryUtils.getBeanNames((ListableBeanFactory) beanFactory,
DataSourceFactoryBean.class);
final List<String> dsBeanNames = new ArrayList<>(
dataSourceBeanNames.size() + dataSourceFactoryBeanNames.size());
dataSourceBeanNames.forEach(n -> dsBeanNames.add(n));
dataSourceFactoryBeanNames.forEach(n -> {
if (!dsBeanNames.contains(n)) {
dsBeanNames.add(n);
}
});
for (String dsBeanName : dsBeanNames) {
// get data context id, if available
String dataContextId = null;
BeanDefinition bd = registry.getBeanDefinition(dsBeanName);
if (bd instanceof DataContextBoundBeanDefinition) {
dataContextId = ((DataContextBoundBeanDefinition) bd).getDataContextId().orElse(null);
}
// register JDBC datastore
JdbcDatastoreRegistrar.registerDatastore(registry, environment, dataContextId, PrimaryMode.AUTO,
dsBeanName, null, true, beanClassLoader);
}
}
}
开发者ID:holon-platform,项目名称:holon-datastore-jdbc,代码行数:32,代码来源:JdbcDatastoreAutoConfigurationRegistrar.java
示例11: postProcessBeanDefinitionRegistry
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void postProcessBeanDefinitionRegistry(final BeanDefinitionRegistry registry) throws BeansException
{
final BeanDefinition renditionServiceDefinition = registry.getBeanDefinition("renditionService");
if (renditionServiceDefinition != null
&& renditionServiceDefinition.getBeanClassName().equals(RenditionServiceImpl.class.getName()))
{
renditionServiceDefinition.setBeanClassName(ArchiveSupportingRenditionServiceImpl.class.getName());
renditionServiceDefinition.getPropertyValues().add("nodeArchiveService", new RuntimeBeanReference("nodeArchiveService"));
}
}
开发者ID:AFaust,项目名称:alfresco-better-trashmanagement,代码行数:15,代码来源:RenditionServiceBeanDefinitionPostProcessor.java
示例12: forceAutoProxyCreatorToUseClassProxying
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
public static void forceAutoProxyCreatorToUseClassProxying(BeanDefinitionRegistry registry) {
if (registry.containsBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME)) {
BeanDefinition definition = registry.getBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME);
definition.getPropertyValues().add("proxyTargetClass", Boolean.TRUE);
}
}
示例13: forceAutoProxyCreatorToExposeProxy
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
static void forceAutoProxyCreatorToExposeProxy(BeanDefinitionRegistry registry) {
if (registry.containsBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME)) {
BeanDefinition definition = registry.getBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME);
definition.getPropertyValues().add("exposeProxy", Boolean.TRUE);
}
}
示例14: registerDatastore
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
/**
* Register a {@link JpaDatastore} bean
* @param registry BeanDefinitionRegistry
* @param dataContextId Data context id
* @param primaryMode Primary mode
* @param entityManagerFactoryBeanName EntityManagerFactory bean name reference
* @param transactional Whether to add transactional behaviour to transactional datastore methods
* @param beanClassLoader Bean class loader
* @return Registered Datastore bean name
*/
public static String registerDatastore(BeanDefinitionRegistry registry, String dataContextId,
PrimaryMode primaryMode, String entityManagerFactoryBeanName, boolean transactional, boolean autoFlush,
ClassLoader beanClassLoader) {
boolean primary = PrimaryMode.TRUE == primaryMode;
if (!primary && PrimaryMode.AUTO == primaryMode) {
if (registry.containsBeanDefinition(entityManagerFactoryBeanName)) {
BeanDefinition bd = registry.getBeanDefinition(entityManagerFactoryBeanName);
primary = bd.isPrimary();
}
}
GenericDataContextBoundBeanDefinition definition = new GenericDataContextBoundBeanDefinition();
definition.setDataContextId(dataContextId);
Class<?> datastoreClass = transactional
? addTransactionalAnnotations(DefaultSpringJpaDatastore.class, dataContextId, beanClassLoader)
: DefaultSpringJpaDatastore.class;
definition.setBeanClass(datastoreClass);
definition.setAutowireCandidate(true);
definition.setPrimary(primary);
definition.setDependsOn(entityManagerFactoryBeanName);
if (dataContextId != null) {
definition.addQualifier(new AutowireCandidateQualifier(Qualifier.class, dataContextId));
}
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("entityManagerFactory", new RuntimeBeanReference(entityManagerFactoryBeanName));
pvs.add("autoFlush", autoFlush);
definition.setPropertyValues(pvs);
String beanName = BeanRegistryUtils.buildBeanName(dataContextId,
EnableJpaDatastore.DEFAULT_DATASTORE_BEAN_NAME);
registry.registerBeanDefinition(beanName, definition);
StringBuilder log = new StringBuilder();
if (dataContextId != null) {
log.append("<Data context id: ");
log.append(dataContextId);
log.append("> ");
}
log.append("Registered JPA Datastore bean with name \"");
log.append(beanName);
log.append("\"");
if (dataContextId != null) {
log.append(" and qualifier \"");
log.append(dataContextId);
log.append("\"");
}
log.append(" bound to EntityManagerFactory bean: ");
log.append(entityManagerFactoryBeanName);
logger.info(log.toString());
return beanName;
}
示例15: registerBeanDefinitions
import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {
// Register JPA beans for every Data context bound DataSource
if (beanFactory instanceof ListableBeanFactory) {
ListableBeanFactory listableBeanFactory = (ListableBeanFactory) beanFactory;
String[] dataSourceBeanNames = listableBeanFactory.getBeanNamesForType(DataSource.class, false, true);
if (dataSourceBeanNames != null) {
for (String dataSourceBeanName : dataSourceBeanNames) {
BeanDefinition bd = registry.getBeanDefinition(dataSourceBeanName);
if (bd instanceof DataContextBoundBeanDefinition) {
String dataContextId = ((DataContextBoundBeanDefinition) bd).getDataContextId().orElse(null);
String emfBeanName = isBeanRegistered(listableBeanFactory, registry, EntityManagerFactory.class,
dataContextId, BeanRegistryUtils.buildBeanName(dataContextId,
EnableJpa.DEFAULT_ENTITYMANAGERFACTORY_BEAN_NAME));
if (emfBeanName == null) {
Map<String, Object> attributes = new HashMap<>();
attributes.put("dataContextId", dataContextId);
attributes.put("dataSourceReference", dataSourceBeanName);
attributes.put("entityPackages", getPackagesToScan(dataContextId));
attributes.put("enableDatastore", Boolean.FALSE);
emfBeanName = JpaRegistrar.registerJpaBeans(registry, beanFactory, environment, attributes,
beanClassLoader);
}
if (emfBeanName != null && isBeanRegistered(listableBeanFactory, registry, JpaDatastore.class,
dataContextId, BeanRegistryUtils.buildBeanName(dataContextId,
EnableJpaDatastore.DEFAULT_DATASTORE_BEAN_NAME)) == null) {
// Register JPA Datastore (transactional)
JpaDatastoreRegistrar.registerDatastore(registry, dataContextId, PrimaryMode.AUTO,
emfBeanName, true, false, beanClassLoader);
}
}
}
}
}
}