Java Code Examples for org.springframework.beans.factory.support.BeanDefinitionBuilder#addConstructorArgValue()
The following examples show how to use
org.springframework.beans.factory.support.BeanDefinitionBuilder#addConstructorArgValue() .
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: ConfigBeanDefinitionParser.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Parse a '{@code declare-parents}' element and register the appropriate * DeclareParentsAdvisor with the BeanDefinitionRegistry encapsulated in the * supplied ParserContext. */ private AbstractBeanDefinition parseDeclareParents(Element declareParentsElement, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(DeclareParentsAdvisor.class); builder.addConstructorArgValue(declareParentsElement.getAttribute(IMPLEMENT_INTERFACE)); builder.addConstructorArgValue(declareParentsElement.getAttribute(TYPE_PATTERN)); String defaultImpl = declareParentsElement.getAttribute(DEFAULT_IMPL); String delegateRef = declareParentsElement.getAttribute(DELEGATE_REF); if (StringUtils.hasText(defaultImpl) && !StringUtils.hasText(delegateRef)) { builder.addConstructorArgValue(defaultImpl); } else if (StringUtils.hasText(delegateRef) && !StringUtils.hasText(defaultImpl)) { builder.addConstructorArgReference(delegateRef); } else { parserContext.getReaderContext().error( "Exactly one of the " + DEFAULT_IMPL + " or " + DELEGATE_REF + " attributes must be specified", declareParentsElement, this.parseState.snapshot()); } AbstractBeanDefinition definition = builder.getBeanDefinition(); definition.setSource(parserContext.extractSource(declareParentsElement)); parserContext.getReaderContext().registerWithGeneratedName(definition); return definition; }
Example 2
Source File: SentinelBeanPostProcessor.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
private void registerBean(String interceptorBeanName, SentinelRestTemplate sentinelRestTemplate, RestTemplate restTemplate) { // register SentinelProtectInterceptor bean DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) applicationContext .getAutowireCapableBeanFactory(); BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder .genericBeanDefinition(SentinelProtectInterceptor.class); beanDefinitionBuilder.addConstructorArgValue(sentinelRestTemplate); beanDefinitionBuilder.addConstructorArgValue(restTemplate); BeanDefinition interceptorBeanDefinition = beanDefinitionBuilder .getRawBeanDefinition(); beanFactory.registerBeanDefinition(interceptorBeanName, interceptorBeanDefinition); }
Example 3
Source File: LoadBalancerClientConfigurationRegistrar.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
private static void registerClientConfiguration(BeanDefinitionRegistry registry, Object name, Object configuration) { BeanDefinitionBuilder builder = BeanDefinitionBuilder .genericBeanDefinition(LoadBalancerClientSpecification.class); builder.addConstructorArgValue(name); builder.addConstructorArgValue(configuration); registry.registerBeanDefinition(name + ".LoadBalancerClientSpecification", builder.getBeanDefinition()); }
Example 4
Source File: AbstractRetrofitClientsRegistrar.java From spring-cloud-square with Apache License 2.0 | 5 votes |
private void registerClientConfiguration(BeanDefinitionRegistry registry, Object name, Object configuration) { BeanDefinitionBuilder builder = BeanDefinitionBuilder .genericBeanDefinition(RetrofitClientSpecification.class); builder.addConstructorArgValue(name); builder.addConstructorArgValue(configuration); registry.registerBeanDefinition( name + "." + RetrofitClientSpecification.class.getSimpleName(), builder.getBeanDefinition()); }
Example 5
Source File: DatabasePopulatorConfigUtils.java From spring-analysis-note with MIT License | 5 votes |
private static BeanDefinition createDatabasePopulator(Element element, List<Element> scripts, String execution) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CompositeDatabasePopulator.class); boolean ignoreFailedDrops = element.getAttribute("ignore-failures").equals("DROPS"); boolean continueOnError = element.getAttribute("ignore-failures").equals("ALL"); ManagedList<BeanMetadataElement> delegates = new ManagedList<>(); for (Element scriptElement : scripts) { String executionAttr = scriptElement.getAttribute("execution"); if (!StringUtils.hasText(executionAttr)) { executionAttr = "INIT"; } if (!execution.equals(executionAttr)) { continue; } BeanDefinitionBuilder delegate = BeanDefinitionBuilder.genericBeanDefinition(ResourceDatabasePopulator.class); delegate.addPropertyValue("ignoreFailedDrops", ignoreFailedDrops); delegate.addPropertyValue("continueOnError", continueOnError); // Use a factory bean for the resources so they can be given an order if a pattern is used BeanDefinitionBuilder resourcesFactory = BeanDefinitionBuilder.genericBeanDefinition(SortedResourcesFactoryBean.class); resourcesFactory.addConstructorArgValue(new TypedStringValue(scriptElement.getAttribute("location"))); delegate.addPropertyValue("scripts", resourcesFactory.getBeanDefinition()); if (StringUtils.hasLength(scriptElement.getAttribute("encoding"))) { delegate.addPropertyValue("sqlScriptEncoding", new TypedStringValue(scriptElement.getAttribute("encoding"))); } String separator = getSeparator(element, scriptElement); if (separator != null) { delegate.addPropertyValue("separator", new TypedStringValue(separator)); } delegates.add(delegate.getBeanDefinition()); } builder.addPropertyValue("populators", delegates); return builder.getBeanDefinition(); }
Example 6
Source File: ArchaiusConfigMapSourceRegistar.java From spring-cloud-kubernetes with Apache License 2.0 | 5 votes |
private void registerSourceConfiguration(BeanDefinitionRegistry registry, Object name, Object namespace) { BeanDefinitionBuilder configMapSourceConfigBuilder = BeanDefinitionBuilder.genericBeanDefinition(ArchaiusConfigMapSourceConfiguration.class); BeanDefinitionBuilder dynamicWatchedConfigBuilder = BeanDefinitionBuilder.genericBeanDefinition(DynamicWatchedConfiguration.class); configMapSourceConfigBuilder.addConstructorArgReference(KUBERNETES_CLIENT_REF); configMapSourceConfigBuilder.addConstructorArgValue(name); configMapSourceConfigBuilder.addConstructorArgValue(namespace); String configMapSourceConfigName = name + CONFIG_MAP_SOURCE_SUFFIX; registry.registerBeanDefinition(configMapSourceConfigName, configMapSourceConfigBuilder.getBeanDefinition()); String dynamicWatchedConfigName = name + DYNAMIC_WATCH_CONFIG_SUFFIX; dynamicWatchedConfigBuilder.addConstructorArgReference(configMapSourceConfigName); registry.registerBeanDefinition(dynamicWatchedConfigName, dynamicWatchedConfigBuilder.getBeanDefinition()); }
Example 7
Source File: DatabasePopulatorConfigUtils.java From lams with GNU General Public License v2.0 | 5 votes |
static private BeanDefinition createDatabasePopulator(Element element, List<Element> scripts, String execution) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CompositeDatabasePopulator.class); boolean ignoreFailedDrops = element.getAttribute("ignore-failures").equals("DROPS"); boolean continueOnError = element.getAttribute("ignore-failures").equals("ALL"); ManagedList<BeanMetadataElement> delegates = new ManagedList<BeanMetadataElement>(); for (Element scriptElement : scripts) { String executionAttr = scriptElement.getAttribute("execution"); if (!StringUtils.hasText(executionAttr)) { executionAttr = "INIT"; } if (!execution.equals(executionAttr)) { continue; } BeanDefinitionBuilder delegate = BeanDefinitionBuilder.genericBeanDefinition(ResourceDatabasePopulator.class); delegate.addPropertyValue("ignoreFailedDrops", ignoreFailedDrops); delegate.addPropertyValue("continueOnError", continueOnError); // Use a factory bean for the resources so they can be given an order if a pattern is used BeanDefinitionBuilder resourcesFactory = BeanDefinitionBuilder.genericBeanDefinition(SortedResourcesFactoryBean.class); resourcesFactory.addConstructorArgValue(new TypedStringValue(scriptElement.getAttribute("location"))); delegate.addPropertyValue("scripts", resourcesFactory.getBeanDefinition()); if (StringUtils.hasLength(scriptElement.getAttribute("encoding"))) { delegate.addPropertyValue("sqlScriptEncoding", new TypedStringValue(scriptElement.getAttribute("encoding"))); } String separator = getSeparator(element, scriptElement); if (separator != null) { delegate.addPropertyValue("separator", new TypedStringValue(separator)); } delegates.add(delegate.getBeanDefinition()); } builder.addPropertyValue("populators", delegates); return builder.getBeanDefinition(); }
Example 8
Source File: ZookeeperBeanDefinitionParser.java From shardingsphere-elasticjob-lite with Apache License 2.0 | 5 votes |
private AbstractBeanDefinition buildZookeeperConfigurationBeanDefinition(final Element element) { BeanDefinitionBuilder configuration = BeanDefinitionBuilder.rootBeanDefinition(ZookeeperConfiguration.class); configuration.addConstructorArgValue(element.getAttribute("server-lists")); configuration.addConstructorArgValue(element.getAttribute("namespace")); addPropertyValueIfNotEmpty("base-sleep-time-milliseconds", "baseSleepTimeMilliseconds", element, configuration); addPropertyValueIfNotEmpty("max-sleep-time-milliseconds", "maxSleepTimeMilliseconds", element, configuration); addPropertyValueIfNotEmpty("max-retries", "maxRetries", element, configuration); addPropertyValueIfNotEmpty("session-timeout-milliseconds", "sessionTimeoutMilliseconds", element, configuration); addPropertyValueIfNotEmpty("connection-timeout-milliseconds", "connectionTimeoutMilliseconds", element, configuration); addPropertyValueIfNotEmpty("digest", "digest", element, configuration); return configuration.getBeanDefinition(); }
Example 9
Source File: ScheduledTasksBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 5 votes |
private RuntimeBeanReference intervalTaskReference(String runnableBeanName, String initialDelay, String interval, Element taskElement, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( "org.springframework.scheduling.config.IntervalTask"); builder.addConstructorArgReference(runnableBeanName); builder.addConstructorArgValue(interval); builder.addConstructorArgValue(StringUtils.hasLength(initialDelay) ? initialDelay : ZERO_INITIAL_DELAY); return beanReference(taskElement, parserContext, builder); }
Example 10
Source File: AutoConfiguration.java From krpc with Apache License 2.0 | 5 votes |
void registerAsyncReferer(String beanName, String interfaceName, DefaultListableBeanFactory beanFactory) { //log.info("register referer "+interfaceName+", beanName="+beanName); BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(RefererFactory.class); beanDefinitionBuilder.addConstructorArgValue(beanName); beanDefinitionBuilder.addConstructorArgValue(interfaceName); beanDefinitionBuilder.addDependsOn("rpcApp"); beanDefinitionBuilder.setLazyInit(true); beanFactory.registerBeanDefinition(beanName, beanDefinitionBuilder.getRawBeanDefinition()); }
Example 11
Source File: DigesterBeanDefinitionParser.java From jasypt with Apache License 2.0 | 5 votes |
@Override protected void doParse(final Element element, final BeanDefinitionBuilder builder) { builder.addConstructorArgValue(new Integer(this.digesterType)); processStringAttribute(element, builder, PARAM_ALGORITHM, "algorithm"); processBeanAttribute(element, builder, PARAM_CONFIG_BEAN, "config"); processIntegerAttribute(element, builder, PARAM_ITERATIONS, "iterations"); processIntegerAttribute(element, builder, PARAM_SALT_SIZE_BYTES, "saltSizeBytes"); processBeanAttribute(element, builder, PARAM_SALT_GENERATOR_BEAN, "saltGenerator"); processBeanAttribute(element, builder, PARAM_PROVIDER_BEAN, "provider"); processStringAttribute(element, builder, PARAM_PROVIDER_NAME, "providerName"); processBooleanAttribute(element, builder, PARAM_INVERT_POSITION_OF_SALT_IN_MESSAGE_BEFORE_DIGESTING, "invertPositionOfSaltInMessageBeforeDigesting"); processBooleanAttribute(element, builder, PARAM_INVERT_POSITION_OF_PLAIN_SALT_IN_ENCRYPTION_RESULTS, "invertPositionOfPlainSaltInEncryptionResults"); processBooleanAttribute(element, builder, PARAM_USE_LENIENT_SALT_SIZE_CHECK, "useLenientSaltSizeCheck"); processIntegerAttribute(element, builder, PARAM_POOL_SIZE, "poolSize"); processStringAttribute(element, builder, PARAM_STRING_OUTPUT_TYPE, "stringOutputType"); processBooleanAttribute(element, builder, PARAM_UNICODE_NORMALIZATION_IGNORED, "unicodeNormalizationIgnored"); processStringAttribute(element, builder, PARAM_PREFIX, "prefix"); processStringAttribute(element, builder, PARAM_SUFFIX, "suffix"); String scope = element.getAttribute(SCOPE_ATTRIBUTE); if (StringUtils.hasLength(scope)) { builder.setScope(scope); } }
Example 12
Source File: DatabasePopulatorConfigUtils.java From java-technology-stack with MIT License | 5 votes |
private static BeanDefinition createDatabasePopulator(Element element, List<Element> scripts, String execution) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CompositeDatabasePopulator.class); boolean ignoreFailedDrops = element.getAttribute("ignore-failures").equals("DROPS"); boolean continueOnError = element.getAttribute("ignore-failures").equals("ALL"); ManagedList<BeanMetadataElement> delegates = new ManagedList<>(); for (Element scriptElement : scripts) { String executionAttr = scriptElement.getAttribute("execution"); if (!StringUtils.hasText(executionAttr)) { executionAttr = "INIT"; } if (!execution.equals(executionAttr)) { continue; } BeanDefinitionBuilder delegate = BeanDefinitionBuilder.genericBeanDefinition(ResourceDatabasePopulator.class); delegate.addPropertyValue("ignoreFailedDrops", ignoreFailedDrops); delegate.addPropertyValue("continueOnError", continueOnError); // Use a factory bean for the resources so they can be given an order if a pattern is used BeanDefinitionBuilder resourcesFactory = BeanDefinitionBuilder.genericBeanDefinition(SortedResourcesFactoryBean.class); resourcesFactory.addConstructorArgValue(new TypedStringValue(scriptElement.getAttribute("location"))); delegate.addPropertyValue("scripts", resourcesFactory.getBeanDefinition()); if (StringUtils.hasLength(scriptElement.getAttribute("encoding"))) { delegate.addPropertyValue("sqlScriptEncoding", new TypedStringValue(scriptElement.getAttribute("encoding"))); } String separator = getSeparator(element, scriptElement); if (separator != null) { delegate.addPropertyValue("separator", new TypedStringValue(separator)); } delegates.add(delegate.getBeanDefinition()); } builder.addPropertyValue("populators", delegates); return builder.getBeanDefinition(); }
Example 13
Source File: AbstractCloudServiceFactoryParser.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { String serviceId = element.getAttribute("service-name"); builder.addConstructorArgValue(serviceConnectorFactoryType); builder.addConstructorArgValue(element.getAttribute(ID_ATTRIBUTE)); builder.addConstructorArgValue(serviceId); // subclasses should add one more constructor parameter for ServiceConnectorConfig }
Example 14
Source File: SimpleDateFormatBeanDefinitionParser.java From Mykit with Apache License 2.0 | 5 votes |
@Override protected void doParse(Element element, BeanDefinitionBuilder bean) { String pattern = element.getAttribute("pattern"); bean.addConstructorArgValue(pattern); // this however is an optional property String lenient = element.getAttribute("lenient"); if (StringUtils.hasText(lenient)) { bean.addPropertyValue("lenient", Boolean.valueOf(lenient)); } }
Example 15
Source File: KeyGenerateStrategyBeanDefinitionParser.java From shardingsphere with Apache License 2.0 | 5 votes |
@Override protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) { BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(KeyGenerateStrategyConfiguration.class); factory.addConstructorArgValue(element.getAttribute(KeyGenerateStrategyBeanDefinitionTag.COLUMN_ATTRIBUTE)); factory.addConstructorArgValue(element.getAttribute(KeyGenerateStrategyBeanDefinitionTag.ALGORITHM_REF_ATTRIBUTE)); return factory.getBeanDefinition(); }
Example 16
Source File: JedisProviderFactoryBean.java From jeesuite-libs with Apache License 2.0 | 4 votes |
/** * */ private void registerRedisProvier() { String beanName = getGroup() + REDIS_PROVIDER_SUFFIX; if(context.containsBean(beanName)){ throw new RuntimeException("已包含group为["+this.group+"]的缓存实例"); } String[] servers = StringUtils.tokenizeToStringArray(this.servers, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS); //检查ip和port格式 for (String server : servers) { if(!pattern.matcher(server).matches()){ throw new RuntimeException("参数servers:"+this.servers+"错误"); } } Class<?> beanClass = null; if(JedisStandaloneProvider.MODE.equalsIgnoreCase(mode)){ beanClass = JedisStandaloneProvider.class; }else if(JedisClusterProvider.MODE.equalsIgnoreCase(mode)){ beanClass = JedisClusterProvider.class; }else if(JedisSentinelProvider.MODE.equalsIgnoreCase(mode)){ beanClass = JedisSentinelProvider.class; // Validate.notBlank(masterName, "Sentinel模式[masterName]参数 required"); }else{ throw new RuntimeException("参数mode:"+this.mode+"不支持"); } DefaultListableBeanFactory acf = (DefaultListableBeanFactory) context.getAutowireCapableBeanFactory(); BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(beanClass); beanDefinitionBuilder.addConstructorArgValue(getGroup())// .addConstructorArgValue(jedisPoolConfig)// .addConstructorArgValue(servers)// .addConstructorArgValue(timeout);// if(JedisStandaloneProvider.MODE.equalsIgnoreCase(mode) || JedisSentinelProvider.MODE.equalsIgnoreCase(mode)){ beanDefinitionBuilder.addConstructorArgValue(org.apache.commons.lang3.StringUtils.trimToNull(password))// .addConstructorArgValue(database)// .addConstructorArgValue(clientName); } if(JedisSentinelProvider.MODE.equalsIgnoreCase(mode)){ beanDefinitionBuilder.addConstructorArgValue(masterName); } acf.registerBeanDefinition(beanName, beanDefinitionBuilder.getRawBeanDefinition()); // logger.info("register JedisProvider OK,Class:{},beanName:{}",beanClass.getSimpleName(),beanName); }
Example 17
Source File: StringBeanDefinitionParser.java From cxf with Apache License 2.0 | 4 votes |
@Override protected void doParse(Element element, BeanDefinitionBuilder builder) { builder.addConstructorArgValue(DOMUtils.getRawContent(element)); }
Example 18
Source File: ShardingStrategyBeanDefinitionParser.java From shardingsphere with Apache License 2.0 | 4 votes |
private AbstractBeanDefinition getHintShardingStrategyConfigBeanDefinition(final Element element) { BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(HintShardingStrategyConfiguration.class); factory.addConstructorArgValue(element.getAttribute(ShardingStrategyBeanDefinitionTag.ALGORITHM_REF_ATTRIBUTE)); return factory.getBeanDefinition(); }
Example 19
Source File: ShardingStrategyBeanDefinitionParser.java From shardingsphere with Apache License 2.0 | 4 votes |
private AbstractBeanDefinition getComplexShardingStrategyConfigBeanDefinition(final Element element) { BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(ComplexShardingStrategyConfiguration.class); factory.addConstructorArgValue(element.getAttribute(ShardingStrategyBeanDefinitionTag.SHARDING_COLUMNS_ATTRIBUTE)); factory.addConstructorArgValue(element.getAttribute(ShardingStrategyBeanDefinitionTag.ALGORITHM_REF_ATTRIBUTE)); return factory.getBeanDefinition(); }
Example 20
Source File: TransactionManagerParser.java From spring-ldap with Apache License 2.0 | 3 votes |
private BeanDefinition parseDifferentSubtreeRenamingStrategy(Element element) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(DifferentSubtreeTempEntryRenamingStrategy.class); String subtreeNode = element.getAttribute(ATT_SUBTREE_NODE); Assert.hasText(subtreeNode, ATT_SUBTREE_NODE + " must be specified"); builder.addConstructorArgValue(subtreeNode); return builder.getBeanDefinition(); }