Java Code Examples for org.springframework.beans.factory.support.RootBeanDefinition#setConstructorArgumentValues()
The following examples show how to use
org.springframework.beans.factory.support.RootBeanDefinition#setConstructorArgumentValues() .
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: VaultRepositoryConfigurationExtension.java From spring-vault with Apache License 2.0 | 6 votes |
@Override protected AbstractBeanDefinition getDefaultKeyValueTemplateBeanDefinition( RepositoryConfigurationSource configurationSource) { RootBeanDefinition keyValueTemplateDefinition = new RootBeanDefinition(VaultKeyValueTemplate.class); ConstructorArgumentValues constructorArgumentValuesForKeyValueTemplate = new ConstructorArgumentValues(); constructorArgumentValuesForKeyValueTemplate.addIndexedArgumentValue(0, new RuntimeBeanReference(VAULT_ADAPTER_BEAN_NAME)); constructorArgumentValuesForKeyValueTemplate.addIndexedArgumentValue(1, new RuntimeBeanReference(VAULT_MAPPING_CONTEXT_BEAN_NAME)); keyValueTemplateDefinition.setConstructorArgumentValues(constructorArgumentValuesForKeyValueTemplate); return keyValueTemplateDefinition; }
Example 2
Source File: KotlinLambdaToFunctionAutoConfiguration.java From spring-cloud-function with Apache License 2.0 | 6 votes |
/** * Will transform all discovered Kotlin's Function lambdas to java * Supplier, Function and Consumer, retaining the original Kotlin type * characteristics. * * @return the bean factory post processor */ @Bean public BeanFactoryPostProcessor kotlinToFunctionTransformer() { return new BeanFactoryPostProcessor() { @Override public void postProcessBeanFactory( ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames(); for (String beanDefinitionName : beanDefinitionNames) { BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanDefinitionName); ResolvableType rt = beanDefinition.getResolvableType(); if (rt.getType().getTypeName().startsWith("kotlin.jvm.functions.Function")) { RootBeanDefinition cbd = new RootBeanDefinition(KotlinFunctionWrapper.class); ConstructorArgumentValues ca = new ConstructorArgumentValues(); ca.addGenericArgumentValue(beanDefinition); cbd.setConstructorArgumentValues(ca); ((BeanDefinitionRegistry) beanFactory).registerBeanDefinition(beanDefinitionName + FunctionRegistration.REGISTRATION_NAME_SUFFIX, cbd); } } } }; }
Example 3
Source File: FunctionProxyApplicationListener.java From spring-cloud-function with Apache License 2.0 | 6 votes |
private void registerByteCodeLoadingProxy(String name, String type, Resource resource, DefaultListableBeanFactory beanFactory) { Class<?> proxyClass = null; if ("supplier".equals(type.toLowerCase())) { proxyClass = ByteCodeLoadingSupplier.class; } else if ("consumer".equals(type.toLowerCase())) { proxyClass = ByteCodeLoadingConsumer.class; } else { proxyClass = ByteCodeLoadingFunction.class; } RootBeanDefinition beanDefinition = new RootBeanDefinition(proxyClass); ConstructorArgumentValues args = new ConstructorArgumentValues(); args.addGenericArgumentValue(resource); beanDefinition.setConstructorArgumentValues(args); beanFactory.registerBeanDefinition(name, beanDefinition); }
Example 4
Source File: ResourcesBeanDefinitionParser.java From spring-analysis-note with MIT License | 5 votes |
private void parseResourceCache(ManagedList<Object> resourceResolvers, ManagedList<Object> resourceTransformers, Element element, @Nullable Object source) { String resourceCache = element.getAttribute("resource-cache"); if ("true".equals(resourceCache)) { ConstructorArgumentValues cargs = new ConstructorArgumentValues(); RootBeanDefinition cachingResolverDef = new RootBeanDefinition(CachingResourceResolver.class); cachingResolverDef.setSource(source); cachingResolverDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); cachingResolverDef.setConstructorArgumentValues(cargs); RootBeanDefinition cachingTransformerDef = new RootBeanDefinition(CachingResourceTransformer.class); cachingTransformerDef.setSource(source); cachingTransformerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); cachingTransformerDef.setConstructorArgumentValues(cargs); String cacheManagerName = element.getAttribute("cache-manager"); String cacheName = element.getAttribute("cache-name"); if (StringUtils.hasText(cacheManagerName) && StringUtils.hasText(cacheName)) { RuntimeBeanReference cacheManagerRef = new RuntimeBeanReference(cacheManagerName); cargs.addIndexedArgumentValue(0, cacheManagerRef); cargs.addIndexedArgumentValue(1, cacheName); } else { ConstructorArgumentValues cacheCavs = new ConstructorArgumentValues(); cacheCavs.addIndexedArgumentValue(0, RESOURCE_CHAIN_CACHE); RootBeanDefinition cacheDef = new RootBeanDefinition(ConcurrentMapCache.class); cacheDef.setSource(source); cacheDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); cacheDef.setConstructorArgumentValues(cacheCavs); cargs.addIndexedArgumentValue(0, cacheDef); } resourceResolvers.add(cachingResolverDef); resourceTransformers.add(cachingTransformerDef); } }
Example 5
Source File: Spr5475Tests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void noArgFactoryMethodInvokedWithTwoArgsAndTypesSpecified() { RootBeanDefinition def = new RootBeanDefinition(Foo.class); def.setFactoryMethodName("noArgFactory"); ConstructorArgumentValues cav = new ConstructorArgumentValues(); cav.addIndexedArgumentValue(0, "bogusArg1", CharSequence.class.getName()); cav.addIndexedArgumentValue(1, "bogusArg2".getBytes()); def.setConstructorArgumentValues(cav); assertExceptionMessageForMisconfiguredFactoryMethod(def, "Error creating bean with name 'foo': No matching factory method found: factory method 'noArgFactory(CharSequence,byte[])'. " + "Check that a method with the specified name and arguments exists and that it is static."); }
Example 6
Source File: ResourcesBeanDefinitionParser.java From java-technology-stack with MIT License | 5 votes |
private void parseResourceCache(ManagedList<Object> resourceResolvers, ManagedList<Object> resourceTransformers, Element element, @Nullable Object source) { String resourceCache = element.getAttribute("resource-cache"); if ("true".equals(resourceCache)) { ConstructorArgumentValues cargs = new ConstructorArgumentValues(); RootBeanDefinition cachingResolverDef = new RootBeanDefinition(CachingResourceResolver.class); cachingResolverDef.setSource(source); cachingResolverDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); cachingResolverDef.setConstructorArgumentValues(cargs); RootBeanDefinition cachingTransformerDef = new RootBeanDefinition(CachingResourceTransformer.class); cachingTransformerDef.setSource(source); cachingTransformerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); cachingTransformerDef.setConstructorArgumentValues(cargs); String cacheManagerName = element.getAttribute("cache-manager"); String cacheName = element.getAttribute("cache-name"); if (StringUtils.hasText(cacheManagerName) && StringUtils.hasText(cacheName)) { RuntimeBeanReference cacheManagerRef = new RuntimeBeanReference(cacheManagerName); cargs.addIndexedArgumentValue(0, cacheManagerRef); cargs.addIndexedArgumentValue(1, cacheName); } else { ConstructorArgumentValues cacheCavs = new ConstructorArgumentValues(); cacheCavs.addIndexedArgumentValue(0, RESOURCE_CHAIN_CACHE); RootBeanDefinition cacheDef = new RootBeanDefinition(ConcurrentMapCache.class); cacheDef.setSource(source); cacheDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); cacheDef.setConstructorArgumentValues(cacheCavs); cargs.addIndexedArgumentValue(0, cacheDef); } resourceResolvers.add(cachingResolverDef); resourceTransformers.add(cachingTransformerDef); } }
Example 7
Source File: Spr5475Tests.java From java-technology-stack with MIT License | 5 votes |
@Test public void noArgFactoryMethodInvokedWithTwoArgsAndTypesSpecified() { RootBeanDefinition def = new RootBeanDefinition(Foo.class); def.setFactoryMethodName("noArgFactory"); ConstructorArgumentValues cav = new ConstructorArgumentValues(); cav.addIndexedArgumentValue(0, "bogusArg1", CharSequence.class.getName()); cav.addIndexedArgumentValue(1, "bogusArg2".getBytes()); def.setConstructorArgumentValues(cav); assertExceptionMessageForMisconfiguredFactoryMethod(def, "Error creating bean with name 'foo': No matching factory method found: factory method 'noArgFactory(CharSequence,byte[])'. " + "Check that a method with the specified name and arguments exists and that it is static."); }
Example 8
Source File: ResourcesBeanDefinitionParser.java From lams with GNU General Public License v2.0 | 5 votes |
private void parseResourceCache(ManagedList<? super Object> resourceResolvers, ManagedList<? super Object> resourceTransformers, Element element, Object source) { String resourceCache = element.getAttribute("resource-cache"); if ("true".equals(resourceCache)) { ConstructorArgumentValues cavs = new ConstructorArgumentValues(); RootBeanDefinition cachingResolverDef = new RootBeanDefinition(CachingResourceResolver.class); cachingResolverDef.setSource(source); cachingResolverDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); cachingResolverDef.setConstructorArgumentValues(cavs); RootBeanDefinition cachingTransformerDef = new RootBeanDefinition(CachingResourceTransformer.class); cachingTransformerDef.setSource(source); cachingTransformerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); cachingTransformerDef.setConstructorArgumentValues(cavs); String cacheManagerName = element.getAttribute("cache-manager"); String cacheName = element.getAttribute("cache-name"); if (StringUtils.hasText(cacheManagerName) && StringUtils.hasText(cacheName)) { RuntimeBeanReference cacheManagerRef = new RuntimeBeanReference(cacheManagerName); cavs.addIndexedArgumentValue(0, cacheManagerRef); cavs.addIndexedArgumentValue(1, cacheName); } else { ConstructorArgumentValues cacheCavs = new ConstructorArgumentValues(); cacheCavs.addIndexedArgumentValue(0, RESOURCE_CHAIN_CACHE); RootBeanDefinition cacheDef = new RootBeanDefinition(ConcurrentMapCache.class); cacheDef.setSource(source); cacheDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); cacheDef.setConstructorArgumentValues(cacheCavs); cavs.addIndexedArgumentValue(0, cacheDef); } resourceResolvers.add(cachingResolverDef); resourceTransformers.add(cachingTransformerDef); } }
Example 9
Source File: ResourcesBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 5 votes |
private void parseResourceCache(ManagedList<? super Object> resourceResolvers, ManagedList<? super Object> resourceTransformers, Element element, Object source) { String resourceCache = element.getAttribute("resource-cache"); if ("true".equals(resourceCache)) { ConstructorArgumentValues cavs = new ConstructorArgumentValues(); RootBeanDefinition cachingResolverDef = new RootBeanDefinition(CachingResourceResolver.class); cachingResolverDef.setSource(source); cachingResolverDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); cachingResolverDef.setConstructorArgumentValues(cavs); RootBeanDefinition cachingTransformerDef = new RootBeanDefinition(CachingResourceTransformer.class); cachingTransformerDef.setSource(source); cachingTransformerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); cachingTransformerDef.setConstructorArgumentValues(cavs); String cacheManagerName = element.getAttribute("cache-manager"); String cacheName = element.getAttribute("cache-name"); if (StringUtils.hasText(cacheManagerName) && StringUtils.hasText(cacheName)) { RuntimeBeanReference cacheManagerRef = new RuntimeBeanReference(cacheManagerName); cavs.addIndexedArgumentValue(0, cacheManagerRef); cavs.addIndexedArgumentValue(1, cacheName); } else { ConstructorArgumentValues cacheCavs = new ConstructorArgumentValues(); cacheCavs.addIndexedArgumentValue(0, RESOURCE_CHAIN_CACHE); RootBeanDefinition cacheDef = new RootBeanDefinition(ConcurrentMapCache.class); cacheDef.setSource(source); cacheDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); cacheDef.setConstructorArgumentValues(cacheCavs); cavs.addIndexedArgumentValue(0, cacheDef); } resourceResolvers.add(cachingResolverDef); resourceTransformers.add(cachingTransformerDef); } }
Example 10
Source File: Spr5475Tests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void noArgFactoryMethodInvokedWithTwoArgsAndTypesSpecified() { RootBeanDefinition def = new RootBeanDefinition(Foo.class); def.setFactoryMethodName("noArgFactory"); ConstructorArgumentValues cav = new ConstructorArgumentValues(); cav.addIndexedArgumentValue(0, "bogusArg1", CharSequence.class.getName()); cav.addIndexedArgumentValue(1, "bogusArg2".getBytes()); def.setConstructorArgumentValues(cav); assertExceptionMessageForMisconfiguredFactoryMethod( def, "Error creating bean with name 'foo': No matching factory method found: factory method 'noArgFactory(CharSequence,byte[])'. " + "Check that a method with the specified name and arguments exists and that it is static."); }
Example 11
Source File: FunctionProxyApplicationListener.java From spring-cloud-function with Apache License 2.0 | 5 votes |
private void registerLambdaCompilingProxy(String name, String type, String inputType, String outputType, String lambda, DefaultListableBeanFactory beanFactory) { Resource resource = new ByteArrayResource(lambda.getBytes()); ConstructorArgumentValues args = new ConstructorArgumentValues(); MutablePropertyValues props = new MutablePropertyValues(); args.addGenericArgumentValue(resource); Class<?> proxyClass = null; if ("supplier".equals(type.toLowerCase())) { proxyClass = LambdaCompilingSupplier.class; args.addGenericArgumentValue(this.supplierCompiler); if (outputType != null) { props.add("typeParameterizations", outputType); } } else if ("consumer".equals(type.toLowerCase())) { proxyClass = LambdaCompilingConsumer.class; args.addGenericArgumentValue(this.consumerCompiler); if (inputType != null) { props.add("typeParameterizations", inputType); } } else { proxyClass = LambdaCompilingFunction.class; args.addGenericArgumentValue(this.functionCompiler); if ((inputType == null && outputType != null) || (outputType == null && inputType != null)) { throw new IllegalArgumentException( "if either input or output type is set, the other is also required"); } if (inputType != null) { props.add("typeParameterizations", new String[] { inputType, outputType }); } } RootBeanDefinition beanDefinition = new RootBeanDefinition(proxyClass); beanDefinition.setConstructorArgumentValues(args); beanDefinition.setPropertyValues(props); beanFactory.registerBeanDefinition(name, beanDefinition); }
Example 12
Source File: HazelcastRepositoryConfigurationExtension.java From spring-data-hazelcast with Apache License 2.0 | 5 votes |
@Override public void registerBeansForRoot(BeanDefinitionRegistry registry, RepositoryConfigurationSource configurationSource) { // register HazelcastKeyValueAdapter String hazelcastInstanceRef = configurationSource.getAttribute("hazelcastInstanceRef").get(); RootBeanDefinition hazelcastKeyValueAdapterDefinition = new RootBeanDefinition(HazelcastKeyValueAdapter.class); ConstructorArgumentValues constructorArgumentValuesForHazelcastKeyValueAdapter = new ConstructorArgumentValues(); constructorArgumentValuesForHazelcastKeyValueAdapter .addIndexedArgumentValue(0, new RuntimeBeanReference(hazelcastInstanceRef)); hazelcastKeyValueAdapterDefinition.setConstructorArgumentValues(constructorArgumentValuesForHazelcastKeyValueAdapter); registerIfNotAlreadyRegistered(() -> hazelcastKeyValueAdapterDefinition, registry, HAZELCAST_ADAPTER_BEAN_NAME, configurationSource); super.registerBeansForRoot(registry, configurationSource); }
Example 13
Source File: HazelcastRepositoryConfigurationExtension.java From spring-data-hazelcast with Apache License 2.0 | 5 votes |
@Override protected AbstractBeanDefinition getDefaultKeyValueTemplateBeanDefinition(RepositoryConfigurationSource configurationSource) { RootBeanDefinition keyValueTemplateDefinition = new RootBeanDefinition(KeyValueTemplate.class); ConstructorArgumentValues constructorArgumentValuesForKeyValueTemplate = new ConstructorArgumentValues(); constructorArgumentValuesForKeyValueTemplate .addIndexedArgumentValue(0, new RuntimeBeanReference(HAZELCAST_ADAPTER_BEAN_NAME)); constructorArgumentValuesForKeyValueTemplate .addIndexedArgumentValue(1, new RuntimeBeanReference(MAPPING_CONTEXT_BEAN_NAME)); keyValueTemplateDefinition.setConstructorArgumentValues(constructorArgumentValuesForKeyValueTemplate); return keyValueTemplateDefinition; }
Example 14
Source File: VaultRepositoryConfigurationExtension.java From spring-vault with Apache License 2.0 | 3 votes |
@Override public void registerBeansForRoot(BeanDefinitionRegistry registry, RepositoryConfigurationSource configurationSource) { Optional<String> vaultTemplateRef = configurationSource.getAttribute("vaultTemplateRef"); RootBeanDefinition mappingContextDefinition = createVaultMappingContext(configurationSource); mappingContextDefinition.setSource(configurationSource.getSource()); registerIfNotAlreadyRegistered(() -> mappingContextDefinition, registry, VAULT_MAPPING_CONTEXT_BEAN_NAME, configurationSource); // register Adapter RootBeanDefinition vaultKeyValueAdapterDefinition = new RootBeanDefinition(VaultKeyValueAdapter.class); ConstructorArgumentValues constructorArgumentValuesForVaultKeyValueAdapter = new ConstructorArgumentValues(); constructorArgumentValuesForVaultKeyValueAdapter.addIndexedArgumentValue(0, new RuntimeBeanReference(vaultTemplateRef.orElse("vaultTemplate"))); vaultKeyValueAdapterDefinition.setConstructorArgumentValues(constructorArgumentValuesForVaultKeyValueAdapter); registerIfNotAlreadyRegistered(() -> vaultKeyValueAdapterDefinition, registry, VAULT_ADAPTER_BEAN_NAME, configurationSource); Optional<String> keyValueTemplateName = configurationSource.getAttribute(KEY_VALUE_TEMPLATE_BEAN_REF_ATTRIBUTE); // No custom template reference configured and no matching bean definition found if (keyValueTemplateName.isPresent() && getDefaultKeyValueTemplateRef().equals(keyValueTemplateName.get()) && !registry.containsBeanDefinition(keyValueTemplateName.get())) { registerIfNotAlreadyRegistered(() -> getDefaultKeyValueTemplateBeanDefinition(configurationSource), registry, keyValueTemplateName.get(), configurationSource.getSource()); } super.registerBeansForRoot(registry, configurationSource); }
Example 15
Source File: VaultRepositoryConfigurationExtension.java From spring-vault with Apache License 2.0 | 3 votes |
private RootBeanDefinition createVaultMappingContext(RepositoryConfigurationSource configurationSource) { ConstructorArgumentValues mappingContextArgs = new ConstructorArgumentValues(); RootBeanDefinition mappingContextBeanDef = new RootBeanDefinition(VaultMappingContext.class); mappingContextBeanDef.setConstructorArgumentValues(mappingContextArgs); mappingContextBeanDef.setSource(configurationSource.getSource()); return mappingContextBeanDef; }