Java Code Examples for org.springframework.beans.factory.support.BeanDefinitionBuilder#setAutowireMode()
The following examples show how to use
org.springframework.beans.factory.support.BeanDefinitionBuilder#setAutowireMode() .
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: CmisRegistrar.java From spring-content with Apache License 2.0 | 6 votes |
BeanDefinition createCmisRepositoryConfigurationDefinition( BeanDefinition cmisFolderRepoBeanDef, BeanDefinition cmisDocumentRepoBeanDef, BeanDefinition cmisDocumentStoreBeanDefinition, AnnotationMetadata annotationMetadata) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CmisRepositoryConfigurationImpl.class); builder.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); builder.getRawBeanDefinition().setSource(annotationMetadata); String beanName = new SpringDataAnnotationBeanNameGenerator().generateBeanName(cmisFolderRepoBeanDef); builder.addPropertyReference("cmisFolderRepository", beanName); beanName = new SpringDataAnnotationBeanNameGenerator().generateBeanName(cmisDocumentRepoBeanDef); builder.addPropertyReference("cmisDocumentRepository", beanName); beanName = StoreUtils.getStoreBeanName(cmisDocumentStoreBeanDefinition); builder.addPropertyReference("cmisDocumentStorage", beanName); builder.addPropertyReference("cmisRepositoryInfo", CMIS_REPOSITORY_INFO); builder.addPropertyReference("cmisTypeDefinitionList", CMIS_TYPE_DEFINITION_LIST); return builder.getBeanDefinition(); }
Example 2
Source File: AbstractApiClentRegistrar.java From onetwo with Apache License 2.0 | 6 votes |
/*** * @see RestApiClientConfiguration#apiClientRestExecutor() * @author wayshall * @param annotationMetadataHelper * @param registry */ @Deprecated protected void regiseterRestExecutor(AnnotationMetadataHelper annotationMetadataHelper, BeanDefinitionRegistry registry){ if(registry.containsBeanDefinition(RestExecutorFactory.REST_EXECUTOR_FACTORY_BEAN_NAME)){ return ; } Class<?> restExecutorFacotryClass = (Class<?>)annotationMetadataHelper.getAttributes().get(ATTRS_REST_EXECUTOR_FACTORY); // RestExecutorFactory factory = null; if(restExecutorFacotryClass==null || restExecutorFacotryClass==RestExecutorFactory.class){ restExecutorFacotryClass = DefaultRestExecutorFactory.class; } BeanDefinitionBuilder definition = BeanDefinitionBuilder.genericBeanDefinition(restExecutorFacotryClass); definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); registry.registerBeanDefinition(RestExecutorFactory.REST_EXECUTOR_FACTORY_BEAN_NAME, definition.getBeanDefinition()); }
Example 3
Source File: RestApiClentRegistrar.java From onetwo with Apache License 2.0 | 6 votes |
@Override protected BeanDefinitionBuilder createApiClientFactoryBeanBuilder(AnnotationMetadata annotationMetadata, AnnotationAttributes attributes) { String className = annotationMetadata.getClassName(); BeanDefinitionBuilder definition = BeanDefinitionBuilder.genericBeanDefinition(DefaultApiClientFactoryBean.class); definition.addPropertyValue("url", resolveUrl(attributes)); definition.addPropertyValue("path", resolvePath(attributes)); // definition.addPropertyValue("name", name); definition.addPropertyValue("interfaceClass", className); // definition.addPropertyValue("restExecutor", getRestExecutor()); definition.addPropertyReference("restExecutor", RestExecutorFactory.REST_EXECUTOR_FACTORY_BEAN_NAME); // definition.addPropertyValue("decode404", attributes.get("decode404")); // definition.addPropertyValue("fallback", attributes.get("fallback")); definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); return definition; }
Example 4
Source File: BeanRegistrar.java From spring-batch-lightmin with Apache License 2.0 | 6 votes |
/** * registers beans within the current application context of the given class with the given parameters * * @param beanClass Class of the bean to be generated * @param beanName unique name of the bean to be generated * @param constructorValues Set of Objects, which will be passed as contructor values * @param constructorReferences Set of Object which will be passed as constructor references * @param propertyValues Map of String,Object which will be passed to the key (property) name as value * @param propertyReferences Map of String,Object which will be passed to the key (property) name as reference * @param dependsOnBeans Set of Strings, which contains depending bean names */ public void registerBean(final Class<?> beanClass, final String beanName, final Set<Object> constructorValues, final Set<String> constructorReferences, final Map<String, Object> propertyValues, final Map<String, String> propertyReferences, final Set<String> dependsOnBeans) { final BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(beanClass); builder.setAutowireMode(AbstractBeanDefinition.DEPENDENCY_CHECK_ALL); addConstructorArgReferences(builder, constructorReferences); addConstructorArgValues(builder, constructorValues); addPropertyReference(builder, propertyReferences); addPropertyValues(builder, propertyValues); addDependsOnBean(builder, dependsOnBeans); final DefaultListableBeanFactory factory = (DefaultListableBeanFactory) context.getBeanFactory(); factory.registerBeanDefinition(beanName, builder.getBeanDefinition()); }
Example 5
Source File: AbstractRetrofitClientsRegistrar.java From spring-cloud-square with Apache License 2.0 | 6 votes |
private void registerRetrofitClient(BeanDefinitionRegistry registry, AnnotationMetadata annotationMetadata, Map<String, Object> attributes) { String className = annotationMetadata.getClassName(); BeanDefinitionBuilder definition = BeanDefinitionBuilder .genericBeanDefinition(getFactoryBeanClass()); validate(attributes); definition.addPropertyValue("url", getUrl(attributes)); String name = getName(attributes); definition.addPropertyValue("name", name); definition.addPropertyValue("type", className); definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); String alias = name + "RetrofitClient"; AbstractBeanDefinition beanDefinition = definition.getBeanDefinition(); beanDefinition.setPrimary(true); String qualifier = getQualifier(attributes); if (StringUtils.hasText(qualifier)) { alias = qualifier; } BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, className, new String[] { alias }); BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry); }
Example 6
Source File: FeignClientsRegistrar.java From spring-cloud-openfeign with Apache License 2.0 | 5 votes |
private void registerFeignClient(BeanDefinitionRegistry registry, AnnotationMetadata annotationMetadata, Map<String, Object> attributes) { String className = annotationMetadata.getClassName(); BeanDefinitionBuilder definition = BeanDefinitionBuilder .genericBeanDefinition(FeignClientFactoryBean.class); validate(attributes); definition.addPropertyValue("url", getUrl(attributes)); definition.addPropertyValue("path", getPath(attributes)); String name = getName(attributes); definition.addPropertyValue("name", name); String contextId = getContextId(attributes); definition.addPropertyValue("contextId", contextId); definition.addPropertyValue("type", className); definition.addPropertyValue("decode404", attributes.get("decode404")); definition.addPropertyValue("fallback", attributes.get("fallback")); definition.addPropertyValue("fallbackFactory", attributes.get("fallbackFactory")); definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); String alias = contextId + "FeignClient"; AbstractBeanDefinition beanDefinition = definition.getBeanDefinition(); beanDefinition.setAttribute(FactoryBean.OBJECT_TYPE_ATTRIBUTE, className); // has a default, won't be null boolean primary = (Boolean) attributes.get("primary"); beanDefinition.setPrimary(primary); String qualifier = getQualifier(attributes); if (StringUtils.hasText(qualifier)) { alias = qualifier; } BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, className, new String[] { alias }); BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry); }
Example 7
Source File: NettyRpcRegistrar.java From BootNettyRpc with Apache License 2.0 | 5 votes |
private void registerRpcClient(BeanDefinitionRegistry registry, AnnotationMetadata annotationMetadata, Map<String, Object> attributes) { String className = annotationMetadata.getClassName(); BeanDefinitionBuilder definition = BeanDefinitionBuilder .genericBeanDefinition( RpcClientEntity.class ); definition.addPropertyValue( "name", attributes.get( "name" ) ); definition.addPropertyValue( "isSyn", attributes.get( "isSyn" ) ); definition.addPropertyValue( "host", attributes.get( "host" ) ); definition.addPropertyValue( "port", attributes.get( "port" ) ); definition.addPropertyValue( "rpcClz", attributes.get( "rpcClz" ) ); definition.addPropertyValue( "traceIdIndex", attributes.get( "traceIdIndex" ) ); definition.setAutowireMode( AbstractBeanDefinition.AUTOWIRE_BY_NAME ); try { definition.addPropertyValue( "interfaze", Class.forName( className ) ); } catch (ClassNotFoundException e) { LOG.error( "Get interface for name error", e ); } // definition.setAutowireMode( AbstractBeanDefinition.AUTOWIRE_BY_TYPE ); String alias = className; AbstractBeanDefinition beanDefinition = definition.getBeanDefinition(); beanDefinition.setPrimary( false ); definition.addPropertyValue( "interceptor", getInterceptor( beanDefinition.getPropertyValues() ) ); BeanDefinitionHolder holder = new BeanDefinitionHolder( beanDefinition, className, new String[]{alias} ); LOG.info( "registerRpcClient:" + className ); BeanDefinitionReaderUtils.registerBeanDefinition( holder, registry ); }
Example 8
Source File: ArangoAuditingRegistrar.java From spring-data with Apache License 2.0 | 5 votes |
@Override protected BeanDefinitionBuilder getAuditHandlerBeanDefinitionBuilder(final AuditingConfiguration configuration) { Assert.notNull(configuration, "AuditingConfiguration must not be null!"); final BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(IsNewAwareAuditingHandler.class); final BeanDefinitionBuilder definition = BeanDefinitionBuilder .genericBeanDefinition(ArangoMappingContextLookup.class); definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR); builder.addConstructorArgValue(definition.getBeanDefinition()); return configureDefaultAuditHandlerAttributes(configuration, builder); }
Example 9
Source File: GeneircApiClentRegistrar.java From onetwo with Apache License 2.0 | 5 votes |
@Override protected BeanDefinitionBuilder createApiClientFactoryBeanBuilder(AnnotationMetadata annotationMetadata, AnnotationAttributes attributes) { String className = annotationMetadata.getClassName(); BeanDefinitionBuilder definition = BeanDefinitionBuilder.genericBeanDefinition(DefaultApiClientFactoryBean.class); definition.addPropertyValue("url", resolveUrl(attributes, annotationMetadata)); definition.addPropertyValue("path", resolvePath(attributes)); definition.addPropertyValue("interfaceClass", className); definition.addPropertyValue("responseHandler", responseHandler); definition.addPropertyReference("restExecutor", RestExecutorFactory.REST_EXECUTOR_FACTORY_BEAN_NAME); definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); return definition; }
Example 10
Source File: Simple2RestApiClentRegistrar.java From onetwo with Apache License 2.0 | 5 votes |
@Override protected BeanDefinitionBuilder createApiClientFactoryBeanBuilder(AnnotationMetadata annotationMetadata, AnnotationAttributes attributes) { String className = annotationMetadata.getClassName(); BeanDefinitionBuilder definition = BeanDefinitionBuilder.genericBeanDefinition(DefaultApiClientFactoryBean.class); definition.addPropertyValue("url", resolveUrl(attributes)); definition.addPropertyValue("path", resolvePath(attributes)); definition.addPropertyValue("interfaceClass", className); definition.addPropertyReference("restExecutor", RestExecutorFactory.REST_EXECUTOR_FACTORY_BEAN_NAME); definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); return definition; }
Example 11
Source File: HasorDefinitionParser.java From hasor with Apache License 2.0 | 5 votes |
protected BeanDefinitionHolder createBeanHolder(String beanType, ParserContext parserContext, Consumer<BeanDefinitionBuilder> buildBean) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(beanType); builder.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT); buildBean.accept(builder); // AbstractBeanDefinition startWithDefine = builder.getBeanDefinition(); String beanName = new DefaultBeanNameGenerator().generateBeanName(startWithDefine, parserContext.getRegistry()); return new BeanDefinitionHolder(startWithDefine, beanName); }
Example 12
Source File: BladeFeignClientsRegistrar.java From blade-tool with GNU Lesser General Public License v3.0 | 4 votes |
private void registerFeignClients(AnnotationMetadata metadata, BeanDefinitionRegistry registry) { List<String> feignClients = SpringFactoriesLoader.loadFactoryNames(getSpringFactoriesLoaderFactoryClass(), getBeanClassLoader()); // 如果 spring.factories 里为空 if (feignClients.isEmpty()) { return; } for (String className : feignClients) { try { Class<?> clazz = beanClassLoader.loadClass(className); AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(clazz, FeignClient.class); if (attributes == null) { continue; } // 如果已经存在该 bean,支持原生的 Feign if (registry.containsBeanDefinition(className)) { continue; } registerClientConfiguration(registry, getClientName(attributes), attributes.get("configuration")); validate(attributes); BeanDefinitionBuilder definition = BeanDefinitionBuilder.genericBeanDefinition(FeignClientFactoryBean.class); definition.addPropertyValue("url", getUrl(attributes)); definition.addPropertyValue("path", getPath(attributes)); String name = getName(attributes); definition.addPropertyValue("name", name); // 兼容最新版本的 spring-cloud-openfeign,尚未发布 StringBuilder aliasBuilder = new StringBuilder(18); if (attributes.containsKey("contextId")) { String contextId = getContextId(attributes); aliasBuilder.append(contextId); definition.addPropertyValue("contextId", contextId); } else { aliasBuilder.append(name); } definition.addPropertyValue("type", className); definition.addPropertyValue("decode404", attributes.get("decode404")); definition.addPropertyValue("fallback", attributes.get("fallback")); definition.addPropertyValue("fallbackFactory", attributes.get("fallbackFactory")); definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); AbstractBeanDefinition beanDefinition = definition.getBeanDefinition(); // alias String alias = aliasBuilder.append("FeignClient").toString(); // has a default, won't be null boolean primary = (Boolean)attributes.get("primary"); beanDefinition.setPrimary(primary); String qualifier = getQualifier(attributes); if (StringUtils.hasText(qualifier)) { alias = qualifier; } BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, className, new String[] { alias }); BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry); } catch (ClassNotFoundException e) { e.printStackTrace(); } } }
Example 13
Source File: ServiceBeanDefinitionParser.java From jdal with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ public AbstractBeanDefinition parse(Element element, ParserContext parserContext) { // default dao and service classes String daoClassName = JPA_DAO_CLASS_NAME; String serviceClassName = PERSISTENT_SERVICE_CLASS_NAME; String name = null; boolean declareService = false; if (element.hasAttribute(DAO_CLASS)) daoClassName = element.getAttribute(DAO_CLASS); if (element.hasAttribute(SERVICE_CLASS)) { serviceClassName = element.getAttribute(SERVICE_CLASS); declareService = true; } if (element.hasAttribute(NAME)) name = element.getAttribute(NAME); if (element.hasAttribute(ENTITY)) { String className = element.getAttribute(ENTITY); if (name == null) { name = StringUtils.uncapitalize( StringUtils.substringAfterLast(className, PropertyUtils.PROPERTY_SEPARATOR)); } parserContext.pushContainingComponent( new CompositeComponentDefinition(name, parserContext.extractSource(element))); // Dao BeanDefinitionBuilder daoBuilder = BeanDefinitionBuilder.genericBeanDefinition(daoClassName); NodeList nl = element.getElementsByTagNameNS(element.getNamespaceURI(), CRITERIA); if (nl.getLength() > 0) { ManagedMap<String, BeanReference> builders = new ManagedMap<String, BeanReference>(nl.getLength()); for (int i = 0; i < nl.getLength(); i++) { Element e = (Element) nl.item(i); builders.put(e.getAttribute(NAME), new RuntimeBeanReference(e.getAttribute(BUILDER))); } daoBuilder.addPropertyValue(CRITERIA_BUILDER_MAP, builders); } daoBuilder.addConstructorArgValue(ClassUtils.resolveClassName(className, null)); daoBuilder.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); String daoBeanName; if (declareService) { // use dao suffix daoBeanName = name + DAO_SUFFIX; registerBeanDefinition(parserContext, daoBuilder, daoBeanName); // register service wrapper String serviceBeanName = name + SERVICE_SUFFIX; BeanDefinitionBuilder serviceBuilder = BeanDefinitionBuilder.genericBeanDefinition(serviceClassName); serviceBuilder.addPropertyReference("dao", daoBeanName); registerBeanDefinition(parserContext, serviceBuilder, serviceBeanName); } else { // use service suffix for dao and declare an alias with dao suffix for compatibility with older api. daoBeanName = name + SERVICE_SUFFIX; String[] aliases = new String[] { name + DAO_SUFFIX }; BeanComponentDefinition bcd = new BeanComponentDefinition(daoBuilder.getBeanDefinition(), daoBeanName, aliases); parserContext.registerBeanComponent(bcd); } parserContext.popAndRegisterContainingComponent(); } return null; }