Java Code Examples for org.springframework.beans.factory.support.BeanDefinitionRegistry#registerAlias()
The following examples show how to use
org.springframework.beans.factory.support.BeanDefinitionRegistry#registerAlias() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigurationTypeRegistrar.java From conf4j with MIT License | 6 votes |
private void registerConfigurationType(BeanDefinitionRegistry registry, AnnotationAttributes attributes) { Class<?> configurationType = attributes.getClass("value"); String[] names = attributes.getStringArray("name"); BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(configurationType); addConf4jConfigurationIndicator(builder.getRawBeanDefinition(), ConfigurationIndicator.MANUAL); String beanName; String[] aliases = null; if (names.length == 0) { beanName = configurationType.getName(); } else if (names.length == 1) { beanName = names[0]; } else { beanName = names[0]; aliases = ArrayUtils.subarray(names, 1, names.length); } registry.registerBeanDefinition(beanName, builder.getBeanDefinition()); if (aliases != null) { for (String alias : aliases) { registry.registerAlias(beanName, alias); } } }
Example 2
Source File: IndexerConfigurationBeanFactoryPostProcessor.java From james-project with Apache License 2.0 | 5 votes |
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { ConfigurationProvider confProvider = beanFactory.getBean(ConfigurationProvider.class); try { HierarchicalConfiguration<ImmutableNode> config = confProvider.getConfiguration("indexer"); String provider = config.getString("provider", "lazyIndex"); BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; String indexer = null; String reIndexer = null; if (provider.equalsIgnoreCase("lazyIndex")) { indexer = "lazyIndex"; reIndexer = "fake-reindexer"; } else if (provider.equalsIgnoreCase("elasticsearch")) { indexer = "elasticsearch-listener"; reIndexer = "reindexer-impl"; } else if (provider.equalsIgnoreCase("luceneIndex")) { indexer = "luceneIndex"; reIndexer = "fake-reindexer"; } if (indexer == null) { throw new ConfigurationException("Indexer provider " + provider + " not supported!"); } registry.registerAlias(indexer, "indexer"); registry.registerAlias(reIndexer, "reindexer"); } catch (ConfigurationException e) { throw new FatalBeanException("Unable to config the indexer", e); } }
Example 3
Source File: ConfigurationBeanFactoryPostProcessor.java From james-project with Apache License 2.0 | 5 votes |
/** * Parse the configuration file and depending on it register the beans */ @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { ConfigurationProvider confProvider = beanFactory.getBean(ConfigurationProvider.class); // loop over the beans for (String name : beans.keySet()) { try { HierarchicalConfiguration<ImmutableNode> config = confProvider.getConfiguration(name); // Get the configuration for the class String repClass = config.getString("[@class]"); // Create the definition and register it BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(repClass).getBeanDefinition(); registry.registerBeanDefinition(name, def); String aliases = beans.get(name); String[] aliasArray = aliases.split(","); // check if we need to register some aliases for this bean if (aliasArray != null) { for (String anAliasArray : aliasArray) { String alias = anAliasArray.trim(); if (alias.length() > 0) { registry.registerAlias(name, anAliasArray); } } } } catch (ConfigurationException e) { throw new FatalBeanException("Unable to parse configuration for bean " + name, e); } } }
Example 4
Source File: QuotaBeanFactoryPostProcessor.java From james-project with Apache License 2.0 | 5 votes |
private void registerAliasForQuotaUpdater(String quotaUpdater, BeanDefinitionRegistry registry) { if (quotaUpdater.equalsIgnoreCase(EVENT)) { registry.registerAlias("eventQuotaUpdater", QUOTA_UPDATER_BEAN); } else if (quotaUpdater.equalsIgnoreCase(FAKE_IMPLEMENTATION)) { registry.registerAlias("noQuotaUpdater", QUOTA_UPDATER_BEAN); } else { throw new FatalBeanException("Unreadable value for Quota Updater : " + quotaUpdater); } }
Example 5
Source File: QuotaBeanFactoryPostProcessor.java From james-project with Apache License 2.0 | 5 votes |
private void registerAliasForQuotaManager(String quotaManager, BeanDefinitionRegistry registry) { if (quotaManager.equalsIgnoreCase(FAKE_IMPLEMENTATION)) { registry.registerAlias("noQuotaManager", QUOTA_MANAGER_BEAN); } else if (quotaManager.equalsIgnoreCase("store")) { registry.registerAlias("storeQuotaManager", QUOTA_MANAGER_BEAN); } else { throw new FatalBeanException("Unreadable value for Quota Manager : " + quotaManager); } }
Example 6
Source File: QuotaBeanFactoryPostProcessor.java From james-project with Apache License 2.0 | 5 votes |
private void registerAliasForMaxQuotaManager(String maxQuotaManager, BeanDefinitionRegistry registry) { if (maxQuotaManager.equalsIgnoreCase(FAKE_IMPLEMENTATION)) { registry.registerAlias("noMaxQuotaManager", MAX_QUOTA_MANAGER); } else if (maxQuotaManager.equalsIgnoreCase(IN_MEMORY_IMPLEMENTATION)) { registry.registerAlias("inMemoryMaxQuotaManager", MAX_QUOTA_MANAGER); } else if (maxQuotaManager.equalsIgnoreCase(JPA_IMPLEMENTATION)) { registry.registerAlias("jpaMaxQuotaManager", MAX_QUOTA_MANAGER); } else { throw new FatalBeanException("Unreadable value for Max Quota Manager : " + maxQuotaManager); } }
Example 7
Source File: QuotaBeanFactoryPostProcessor.java From james-project with Apache License 2.0 | 5 votes |
private void registerAliasForCurrentQuotaManager(String currentQuotaManager, BeanDefinitionRegistry registry) { if (currentQuotaManager.equalsIgnoreCase(IN_MEMORY_IMPLEMENTATION)) { registry.registerAlias("inMemoryCurrentQuotaManager", CURRENT_QUOTA_MANAGER_BEAN); } else if (currentQuotaManager.equalsIgnoreCase(JPA_IMPLEMENTATION)) { registry.registerAlias("jpaCurrentQuotaManager", CURRENT_QUOTA_MANAGER_BEAN); } else if (! currentQuotaManager.equalsIgnoreCase("none")) { throw new FatalBeanException("Unreadable value for Current Quota Manager : " + currentQuotaManager); } }
Example 8
Source File: QuotaBeanFactoryPostProcessor.java From james-project with Apache License 2.0 | 5 votes |
private void registerAliasForQuotaRootResolver(String quotaRootResolver, BeanDefinitionRegistry registry) { if (quotaRootResolver.equals(DEFAULT_IMPLEMENTATION)) { registry.registerAlias("defaultQuotaRootResolver", QUOTA_ROOT_RESOLVER_BEAN); } else { throw new FatalBeanException("Unreadable value for QUOTA ROOT resolver : " + quotaRootResolver); } }
Example 9
Source File: AmazonWebserviceClientConfigurationUtils.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
public static void replaceDefaultRegionProvider(BeanDefinitionRegistry registry, String customGlobalRegionProvider) { if (registry.containsBeanDefinition(REGION_PROVIDER_BEAN_NAME)) { registry.removeBeanDefinition(REGION_PROVIDER_BEAN_NAME); } registry.registerAlias(customGlobalRegionProvider, REGION_PROVIDER_BEAN_NAME); }
Example 10
Source File: AmazonWebserviceClientConfigurationUtils.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
public static void replaceDefaultCredentialsProvider(BeanDefinitionRegistry registry, String customGlobalCredentialsProvider) { if (registry.containsBeanDefinition(CREDENTIALS_PROVIDER_BEAN_NAME)) { registry.removeBeanDefinition(CREDENTIALS_PROVIDER_BEAN_NAME); } registry.registerAlias(customGlobalCredentialsProvider, CREDENTIALS_PROVIDER_BEAN_NAME); }
Example 11
Source File: GspAutoConfiguration.java From grails-boot with Apache License 2.0 | 5 votes |
@Override public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { if(!registry.containsBeanDefinition("gspTagLibraryLookup")) { GenericBeanDefinition beanDefinition = createBeanDefinition(StandaloneTagLibraryLookup.class); ManagedList<BeanDefinition> list = new ManagedList<BeanDefinition>(); registerTagLibs(list); beanDefinition.getPropertyValues().addPropertyValue("tagLibInstances", list); registry.registerBeanDefinition("gspTagLibraryLookup", beanDefinition); registry.registerAlias("gspTagLibraryLookup", "tagLibraryLookup"); } }
Example 12
Source File: GspAutoConfiguration.java From grails-boot with Apache License 2.0 | 5 votes |
@Override public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { if(removeDefaultViewResolverBean) { if(registry.containsBeanDefinition("defaultViewResolver")) { registry.removeBeanDefinition("defaultViewResolver"); } } if(replaceViewResolverBean) { if(registry.containsBeanDefinition("viewResolver")) { registry.removeBeanDefinition("viewResolver"); } registry.registerAlias("gspViewResolver", "viewResolver"); } }
Example 13
Source File: AlfrescoRestRegistrar.java From alfresco-mvc with Apache License 2.0 | 5 votes |
private void processDispatcherWebscript(AnnotationAttributes webscriptAttributes, BeanDefinitionRegistry registry) { String webscript = webscriptAttributes.getString("name"); Assert.hasText(webscript, "Webscript name cannot be empty!"); Class<?> servletContext = webscriptAttributes.getClass("servletContext"); ServletConfigOptions[] servletConfigOptions = (ServletConfigOptions[]) webscriptAttributes .get("servletConfigOptions"); Class<? extends WebApplicationContext> servletContextClass = webscriptAttributes .getClass("servletContextClass"); HttpMethod[] httpMethods = (HttpMethod[]) webscriptAttributes.get("httpMethods"); boolean inheritGlobalProperties = (Boolean) webscriptAttributes.get("inheritGlobalProperties"); GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(DispatcherWebscript.class); DispatcherWebscript ws = new DispatcherWebscript(webscript, inheritGlobalProperties); ws.setContextClass(servletContextClass); ws.setContextConfigLocation(servletContext.getName()); ws.addServletConfigOptions(servletConfigOptions); beanDefinition.setInstanceSupplier(() -> ws); beanDefinition.setRole(BeanDefinition.ROLE_APPLICATION); registry.registerBeanDefinition(webscript, beanDefinition); for (HttpMethod httpMethod : httpMethods) { registry.registerAlias(webscript, getWebscriptName(webscript, httpMethod)); } }
Example 14
Source File: DataSourceAutoConfiguration.java From spring-boot-starter-dao with Apache License 2.0 | 4 votes |
private void registryBean(String druidNodeName, MybatisNodeProperties nodeProperties, DruidProperties defaultProperties, Configuration configuration, BeanDefinitionRegistry registry) { if (nodeProperties == null) { return; } String mapperPackage = nodeProperties.getMapperPackage(); String typeAliasesPackage = nodeProperties.getTypeAliasesPackage(); String dbType = super.getDbType(nodeProperties.getMaster(), defaultProperties); Order order = nodeProperties.getOrder(); Dialect dialect = nodeProperties.getDialect(); Style style = nodeProperties.getStyle(); if (null == dialect) { dialect = Dialect.valoueOfName(dbType); } Mapper mappers = nodeProperties.getMapper(); if (mappers == null) { mappers = Mapper.valueOfDialect(dialect); } String basepackage = nodeProperties.getBasePackage(); if (StringUtils.isEmpty(basepackage)) { log.warn("BasePackage为空,db配置异常,当前配置数据源对象的名字{}", druidNodeName); basepackage = ""; } boolean primary = nodeProperties.isPrimary(); String dataSourceName = druidNodeName + "DataSource"; // String dataSourceMasterName = druidNodeName + "DataSource-Master"; String jdbcTemplateName = druidNodeName + "JdbcTemplate"; String transactionManagerName = druidNodeName; String sqlSessionFactoryBeanName = druidNodeName + "RegerSqlSessionFactoryBean"; String scannerConfigurerName = druidNodeName + "RegerScannerConfigurer"; AbstractBeanDefinition dataSource = super.createDataSource(nodeProperties, defaultProperties, dataSourceName); // AbstractBeanDefinition dataSourceMaster = // super.createDataSourceMaster(dataSourceName); AbstractBeanDefinition jdbcTemplate = super.createJdbcTemplate(dataSourceName); AbstractBeanDefinition transactionManager = super.createTransactionManager(dataSourceName); AbstractBeanDefinition sqlSessionFactoryBean = super.createSqlSessionFactoryBean(dataSourceName, mapperPackage, typeAliasesPackage, dialect, configuration); AbstractBeanDefinition scannerConfigurer = super.createScannerConfigurerBean(sqlSessionFactoryBeanName, basepackage, mappers, order, style,nodeProperties.getProperties()); dataSource.setLazyInit(true); dataSource.setPrimary(primary); dataSource.setScope(BeanDefinition.SCOPE_SINGLETON); // dataSourceMaster.setLazyInit(true); // dataSourceMaster.setScope(BeanDefinition.SCOPE_SINGLETON); jdbcTemplate.setLazyInit(true); jdbcTemplate.setPrimary(primary); jdbcTemplate.setScope(BeanDefinition.SCOPE_SINGLETON); transactionManager.setLazyInit(true); transactionManager.setPrimary(primary); transactionManager.setScope(BeanDefinition.SCOPE_SINGLETON); sqlSessionFactoryBean.setLazyInit(true); sqlSessionFactoryBean.setPrimary(primary); sqlSessionFactoryBean.setScope(BeanDefinition.SCOPE_SINGLETON); scannerConfigurer.setLazyInit(true); scannerConfigurer.setPrimary(primary); scannerConfigurer.setScope(BeanDefinition.SCOPE_SINGLETON); registry.registerBeanDefinition(dataSourceName, dataSource); // registry.registerBeanDefinition(dataSourceMasterName, // dataSourceMaster); registry.registerBeanDefinition(jdbcTemplateName, jdbcTemplate); registry.registerBeanDefinition(transactionManagerName, transactionManager); registry.registerBeanDefinition(sqlSessionFactoryBeanName, sqlSessionFactoryBean); registry.registerBeanDefinition(scannerConfigurerName, scannerConfigurer); if (primary) { registry.registerAlias(dataSourceName, "dataSource"); registry.registerAlias(jdbcTemplateName, "jdbcTemplate"); registry.registerAlias(transactionManagerName, "transactionManager"); } }
Example 15
Source File: MailboxConfigurationBeanFactoryPostProcessor.java From james-project with Apache License 2.0 | 4 votes |
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { ConfigurationProvider confProvider = beanFactory.getBean(ConfigurationProvider.class); try { HierarchicalConfiguration<ImmutableNode> config = confProvider.getConfiguration("mailbox"); String provider = config.getString("provider", "jpa"); BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; String mailbox = null; String subscription = null; String messageMapperFactory = null; String mailboxIdDeserializer = null; String mailboxIdFactory = null; if (provider.equalsIgnoreCase("jpa")) { mailbox = JPA_MAILBOXMANAGER; subscription = "jpa-subscriptionManager"; messageMapperFactory = "jpa-sessionMapperFactory"; mailboxIdDeserializer = "jpa-mailbox-id-deserializer"; mailboxIdFactory = "jpa-mailboxIdFactory"; } else if (provider.equalsIgnoreCase("memory")) { mailbox = MEMORY_MAILBOX_MANAGER; subscription = "memory-subscriptionManager"; messageMapperFactory = "memory-sessionMapperFactory"; mailboxIdDeserializer = "memory-mailbox-id-deserializer"; mailboxIdFactory = "memory-mailboxIdFactory"; } else if (provider.equalsIgnoreCase("maildir")) { mailbox = MAILDIR_MAILBOXMANAGER; subscription = "maildir-subscriptionManager"; messageMapperFactory = "maildir-sessionMapperFactory"; mailboxIdDeserializer = "maildir-mailbox-id-deserializer"; mailboxIdFactory = "maildir-mailboxIdFactory"; } if (mailbox == null) { throw new ConfigurationException("Mailboxmanager provider " + provider + " not supported!"); } registry.registerAlias(mailbox, "mailboxmanager"); registry.registerAlias(subscription, "subscriptionManager"); registry.registerAlias(messageMapperFactory, "messageMapperFactory"); registry.registerAlias(mailboxIdDeserializer, "mailbox-id-deserializer"); registry.registerAlias(mailboxIdFactory, "mailboxIdFactory"); removeMailboxManagersExceptRightSelectedOne(registry, mailbox); } catch (ConfigurationException e) { throw new FatalBeanException("Unable to config the mailboxmanager", e); } }