org.springframework.beans.factory.annotation.AnnotatedBeanDefinition Java Examples
The following examples show how to use
org.springframework.beans.factory.annotation.AnnotatedBeanDefinition.
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: AnnotationBeanDefinitionRegistryPostProcessor.java From spring-context-support with Apache License 2.0 | 6 votes |
private void registerBeanDefinitions(BeanDefinitionRegistry registry, String[] basePackages) { ExposingClassPathBeanDefinitionScanner scanner = new ExposingClassPathBeanDefinitionScanner(registry, false, getEnvironment(), getResourceLoader()); BeanNameGenerator beanNameGenerator = resolveAnnotatedBeanNameGenerator(registry); // Set the BeanNameGenerator scanner.setBeanNameGenerator(beanNameGenerator); // Add the AnnotationTypeFilter for annotationTypes for (Class<? extends Annotation> supportedAnnotationType : getSupportedAnnotationTypes()) { scanner.addIncludeFilter(new AnnotationTypeFilter(supportedAnnotationType)); } // Register the primary BeanDefinitions Map<String, AnnotatedBeanDefinition> primaryBeanDefinitions = registerPrimaryBeanDefinitions(scanner, basePackages); // Register the secondary BeanDefinitions registerSecondaryBeanDefinitions(scanner, primaryBeanDefinitions, basePackages); }
Example #2
Source File: AnnotationConfigUtils.java From lams with GNU General Public License v2.0 | 6 votes |
static void processCommonDefinitionAnnotations(AnnotatedBeanDefinition abd, AnnotatedTypeMetadata metadata) { if (metadata.isAnnotated(Lazy.class.getName())) { abd.setLazyInit(attributesFor(metadata, Lazy.class).getBoolean("value")); } else if (abd.getMetadata() != metadata && abd.getMetadata().isAnnotated(Lazy.class.getName())) { abd.setLazyInit(attributesFor(abd.getMetadata(), Lazy.class).getBoolean("value")); } if (metadata.isAnnotated(Primary.class.getName())) { abd.setPrimary(true); } if (metadata.isAnnotated(DependsOn.class.getName())) { abd.setDependsOn(attributesFor(metadata, DependsOn.class).getStringArray("value")); } if (abd instanceof AbstractBeanDefinition) { AbstractBeanDefinition absBd = (AbstractBeanDefinition) abd; if (metadata.isAnnotated(Role.class.getName())) { absBd.setRole(attributesFor(metadata, Role.class).getNumber("value").intValue()); } if (metadata.isAnnotated(Description.class.getName())) { absBd.setDescription(attributesFor(metadata, Description.class).getString("value")); } } }
Example #3
Source File: NetworkAssemble.java From network-spring-boot-starter with Apache License 2.0 | 6 votes |
@Override public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { ClassPathScanningCandidateComponentProvider scanner = new ScanningComponent(Boolean.FALSE, this.environment); scanner.setResourceLoader(this.resourceLoader); AnnotationTypeFilter annotationTypeFilter = new AnnotationTypeFilter(Network.class); scanner.addIncludeFilter(annotationTypeFilter); String packageName = ClassUtils.getPackageName(importingClassMetadata.getClassName()); Set<BeanDefinition> candidateComponents = scanner.findCandidateComponents(packageName); candidateComponents.forEach(beanDefinition -> { AnnotatedBeanDefinition annotatedBeanDefinition = (AnnotatedBeanDefinition) beanDefinition; AnnotationMetadata annotationMetadata = annotatedBeanDefinition.getMetadata(); BeanDefinitionBuilder definition = BeanDefinitionBuilder.genericBeanDefinition(NetworkFactory.class); String className = annotationMetadata.getClassName(); definition.addPropertyValue(NetworkFactoryConstants.PROPERTY_VALUE.getValue(), className); definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); AbstractBeanDefinition abstractBeanDefinition = definition.getBeanDefinition(); BeanDefinitionHolder holder = new BeanDefinitionHolder(abstractBeanDefinition, className); BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry); }); }
Example #4
Source File: DubboLoadBalancedRestTemplateAutoConfiguration.java From spring-cloud-alibaba with Apache License 2.0 | 6 votes |
/** * Gets the annotation attributes {@link RestTemplate} bean being annotated * {@link DubboTransported @DubboTransported}. * @param beanName the bean name of {@link LoadBalanced @LoadBalanced} * {@link RestTemplate} * @param attributesResolver {@link DubboTransportedAttributesResolver} * @return non-null {@link Map} */ private Map<String, Object> getDubboTranslatedAttributes(String beanName, DubboTransportedAttributesResolver attributesResolver) { Map<String, Object> attributes = Collections.emptyMap(); BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName); if (beanDefinition instanceof AnnotatedBeanDefinition) { AnnotatedBeanDefinition annotatedBeanDefinition = (AnnotatedBeanDefinition) beanDefinition; MethodMetadata factoryMethodMetadata = annotatedBeanDefinition .getFactoryMethodMetadata(); attributes = factoryMethodMetadata != null ? Optional .ofNullable(factoryMethodMetadata .getAnnotationAttributes(DUBBO_TRANSPORTED_CLASS_NAME)) .orElse(attributes) : Collections.emptyMap(); } return attributesResolver.resolve(attributes); }
Example #5
Source File: AnnotationBeanNameGenerator.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Derive a bean name from one of the annotations on the class. * @param annotatedDef the annotation-aware bean definition * @return the bean name, or {@code null} if none is found */ protected String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) { AnnotationMetadata amd = annotatedDef.getMetadata(); Set<String> types = amd.getAnnotationTypes(); String beanName = null; for (String type : types) { AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(amd, type); if (isStereotypeWithNameValue(type, amd.getMetaAnnotationTypes(type), attributes)) { Object value = attributes.get("value"); if (value instanceof String) { String strVal = (String) value; if (StringUtils.hasLength(strVal)) { if (beanName != null && !strVal.equals(beanName)) { throw new IllegalStateException("Stereotype annotations suggest inconsistent " + "component names: '" + beanName + "' versus '" + strVal + "'"); } beanName = strVal; } } } } return beanName; }
Example #6
Source File: NettyRpcRegistrar.java From BootNettyRpc with Apache License 2.0 | 6 votes |
protected ClassPathScanningCandidateComponentProvider getScanner() { return new ClassPathScanningCandidateComponentProvider( false, this.environment ) { @Override protected boolean isCandidateComponent( AnnotatedBeanDefinition beanDefinition) { if (beanDefinition.getMetadata().isIndependent()) { if (beanDefinition.getMetadata().isInterface() && beanDefinition.getMetadata().getInterfaceNames().length == 1 && Annotation.class.getName().equals( beanDefinition.getMetadata().getInterfaceNames()[0] )) { try { Class<?> target = ClassUtils.forName( beanDefinition.getMetadata().getClassName(), NettyRpcRegistrar.this.classLoader ); return !target.isAnnotation(); } catch (Exception ex) { this.logger.error( "Could not load target class: " + beanDefinition.getMetadata().getClassName(), ex ); } } return true; } return false; } }; }
Example #7
Source File: FlowerClassPathBeanDefinitionScanner.java From flower with Apache License 2.0 | 6 votes |
public Set<BeanDefinitionHolder> doScan(String... basePackages) { Assert.notEmpty(basePackages, "At least one base package must be specified"); Set<BeanDefinitionHolder> beanDefinitions = new LinkedHashSet<>(); for (String basePackage : basePackages) { Set<BeanDefinition> candidates = findCandidateComponents(basePackage); for (BeanDefinition candidate : candidates) { ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(candidate); candidate.setScope(scopeMetadata.getScopeName()); String beanName = this.beanNameGenerator.generateBeanName(candidate, this.getRegistry()); if (candidate instanceof AbstractBeanDefinition) { postProcessBeanDefinition((AbstractBeanDefinition) candidate, beanName); } if (candidate instanceof AnnotatedBeanDefinition) { AnnotationConfigUtils.processCommonDefinitionAnnotations((AnnotatedBeanDefinition) candidate); } if (checkCandidate(beanName, candidate)) { BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(candidate, beanName); beanDefinitions.add(definitionHolder); } } } return beanDefinitions; }
Example #8
Source File: AnnotationBeanNameGenerator.java From faster-framework-project with Apache License 2.0 | 6 votes |
/** * Derive a bean name from one of the annotations on the class. * * @param annotatedDef the annotation-aware bean definition * @return the bean name, or {@code null} if none is found */ protected String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) { AnnotationMetadata amd = annotatedDef.getMetadata(); Set<String> types = amd.getAnnotationTypes(); String beanName = null; for (String type : types) { AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(amd, type); if (isStereotypeWithNameValue(type, amd.getMetaAnnotationTypes(type), attributes)) { Object value = attributes.get("value"); if (value instanceof String) { String strVal = (String) value; if (StringUtils.hasLength(strVal)) { if (beanName != null && !strVal.equals(beanName)) { throw new IllegalStateException("Stereotype annotations suggest inconsistent " + "component names: '" + beanName + "' versus '" + strVal + "'"); } beanName = strVal; } } } } return beanName; }
Example #9
Source File: JGivenBeanFactoryPostProcessor.java From JGiven with Apache License 2.0 | 6 votes |
@Override public void postProcessBeanFactory( ConfigurableListableBeanFactory beanFactory ) throws BeansException { String[] beanNames = beanFactory.getBeanDefinitionNames(); for( String beanName : beanNames ) { if( beanFactory.containsBeanDefinition( beanName ) ) { BeanDefinition beanDefinition = beanFactory.getBeanDefinition( beanName ); if( beanDefinition instanceof AnnotatedBeanDefinition ) { AnnotatedBeanDefinition annotatedBeanDefinition = (AnnotatedBeanDefinition) beanDefinition; if( annotatedBeanDefinition.getMetadata().hasAnnotation( JGivenStage.class.getName() ) ) { String className = beanDefinition.getBeanClassName(); Class<?> stageClass = createStageClass( beanName, className ); beanDefinition.setBeanClassName( stageClass.getName() ); } } } } }
Example #10
Source File: AnnotationScopeMetadataResolver.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public ScopeMetadata resolveScopeMetadata(BeanDefinition definition) { ScopeMetadata metadata = new ScopeMetadata(); if (definition instanceof AnnotatedBeanDefinition) { AnnotatedBeanDefinition annDef = (AnnotatedBeanDefinition) definition; AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor( annDef.getMetadata(), this.scopeAnnotationType); if (attributes != null) { metadata.setScopeName(attributes.getString("value")); ScopedProxyMode proxyMode = attributes.getEnum("proxyMode"); if (proxyMode == null || proxyMode == ScopedProxyMode.DEFAULT) { proxyMode = this.defaultProxyMode; } metadata.setScopedProxyMode(proxyMode); } } return metadata; }
Example #11
Source File: NettyRpcClientBeanDefinitionRegistrar.java From spring-boot-protocol with Apache License 2.0 | 6 votes |
private void registerNettyRpcClient(AnnotatedBeanDefinition beanDefinition,BeanDefinitionRegistry registry) { AnnotationMetadata metadata = beanDefinition.getMetadata(); Map<String, Object> nettyRpcClientAttributes = metadata.getAnnotationAttributes(nettyRpcClientCanonicalName); Map<String, Object> lazyAttributes = metadata.getAnnotationAttributes(lazyCanonicalName); Class<?> beanClass; try { beanClass = ClassUtils.forName(metadata.getClassName(), classLoader); } catch (ClassNotFoundException e) { throw new BeanCreationException("NettyRpcClientsRegistrar failure! notfound class",e); } String serviceName = resolve((String) nettyRpcClientAttributes.get("serviceName")); beanDefinition.setLazyInit(lazyAttributes == null || Boolean.TRUE.equals(lazyAttributes.get("value"))); ((AbstractBeanDefinition)beanDefinition).setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); ((AbstractBeanDefinition)beanDefinition).setInstanceSupplier(newInstanceSupplier(beanClass,serviceName,(int)nettyRpcClientAttributes.get("timeout"))); String beanName = generateBeanName(beanDefinition.getBeanClassName()); registry.registerBeanDefinition(beanName,beanDefinition); }
Example #12
Source File: AnnotationConfigUtils.java From spring4-understanding with Apache License 2.0 | 6 votes |
static void processCommonDefinitionAnnotations(AnnotatedBeanDefinition abd, AnnotatedTypeMetadata metadata) { if (metadata.isAnnotated(Lazy.class.getName())) { abd.setLazyInit(attributesFor(metadata, Lazy.class).getBoolean("value")); } else if (abd.getMetadata() != metadata && abd.getMetadata().isAnnotated(Lazy.class.getName())) { abd.setLazyInit(attributesFor(abd.getMetadata(), Lazy.class).getBoolean("value")); } if (metadata.isAnnotated(Primary.class.getName())) { abd.setPrimary(true); } if (metadata.isAnnotated(DependsOn.class.getName())) { abd.setDependsOn(attributesFor(metadata, DependsOn.class).getStringArray("value")); } if (abd instanceof AbstractBeanDefinition) { AbstractBeanDefinition absBd = (AbstractBeanDefinition) abd; if (metadata.isAnnotated(Role.class.getName())) { absBd.setRole(attributesFor(metadata, Role.class).getNumber("value").intValue()); } if (metadata.isAnnotated(Description.class.getName())) { absBd.setDescription(attributesFor(metadata, Description.class).getString("value")); } } }
Example #13
Source File: AnnotationBeanNameGenerator.java From java-technology-stack with MIT License | 6 votes |
/** * Derive a bean name from one of the annotations on the class. * @param annotatedDef the annotation-aware bean definition * @return the bean name, or {@code null} if none is found */ @Nullable protected String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) { AnnotationMetadata amd = annotatedDef.getMetadata(); Set<String> types = amd.getAnnotationTypes(); String beanName = null; for (String type : types) { AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(amd, type); if (attributes != null && isStereotypeWithNameValue(type, amd.getMetaAnnotationTypes(type), attributes)) { Object value = attributes.get("value"); if (value instanceof String) { String strVal = (String) value; if (StringUtils.hasLength(strVal)) { if (beanName != null && !strVal.equals(beanName)) { throw new IllegalStateException("Stereotype annotations suggest inconsistent " + "component names: '" + beanName + "' versus '" + strVal + "'"); } beanName = strVal; } } } } return beanName; }
Example #14
Source File: AnnotationNacosPropertySourceBuilder.java From nacos-spring-project with Apache License 2.0 | 6 votes |
@Override protected Map<String, Object>[] resolveRuntimeAttributesArray( AnnotatedBeanDefinition beanDefinition, Properties globalNacosProperties) { // Get AnnotationMetadata AnnotationMetadata metadata = beanDefinition.getMetadata(); Set<String> annotationTypes = metadata.getAnnotationTypes(); List<Map<String, Object>> annotationAttributesList = new LinkedList<Map<String, Object>>(); for (String annotationType : annotationTypes) { annotationAttributesList .addAll(getAnnotationAttributesList(metadata, annotationType)); } return annotationAttributesList.toArray(new Map[0]); }
Example #15
Source File: AnnotationBeanNameGeneratorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * @since 4.0.1 * @see https://jira.spring.io/browse/SPR-11360 */ @Test public void generateBeanNameFromComposedControllerAnnotationWithStringValue() { BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry(); AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition( ComposedControllerAnnotationWithStringValue.class); String beanName = this.beanNameGenerator.generateBeanName(bd, registry); assertEquals("restController", beanName); }
Example #16
Source File: FeignClientsRegistrar.java From spring-cloud-openfeign with Apache License 2.0 | 5 votes |
protected ClassPathScanningCandidateComponentProvider getScanner() { return new ClassPathScanningCandidateComponentProvider(false, this.environment) { @Override protected boolean isCandidateComponent( AnnotatedBeanDefinition beanDefinition) { boolean isCandidate = false; if (beanDefinition.getMetadata().isIndependent()) { if (!beanDefinition.getMetadata().isAnnotation()) { isCandidate = true; } } return isCandidate; } }; }
Example #17
Source File: AnnotationBeanNameGeneratorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * @since 4.0.1 * @see https://jira.spring.io/browse/SPR-11360 */ @Test public void generateBeanNameFromComposedControllerAnnotationWithBlankName() { BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry(); AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComposedControllerAnnotationWithBlankName.class); String beanName = this.beanNameGenerator.generateBeanName(bd, registry); String expectedGeneratedBeanName = this.beanNameGenerator.buildDefaultBeanName(bd); assertEquals(expectedGeneratedBeanName, beanName); }
Example #18
Source File: ClassPathBeanDefinitionScanner.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Perform a scan within the specified base packages, * returning the registered bean definitions. * <p>This method does <i>not</i> register an annotation config processor * but rather leaves this up to the caller. * @param basePackages the packages to check for annotated classes * @return set of beans registered if any for tooling registration purposes (never {@code null}) */ protected Set<BeanDefinitionHolder> doScan(String... basePackages) { Assert.notEmpty(basePackages, "At least one base package must be specified"); Set<BeanDefinitionHolder> beanDefinitions = new LinkedHashSet<BeanDefinitionHolder>(); for (String basePackage : basePackages) { Set<BeanDefinition> candidates = findCandidateComponents(basePackage); for (BeanDefinition candidate : candidates) { ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(candidate); candidate.setScope(scopeMetadata.getScopeName()); String beanName = this.beanNameGenerator.generateBeanName(candidate, this.registry); if (candidate instanceof AbstractBeanDefinition) { postProcessBeanDefinition((AbstractBeanDefinition) candidate, beanName); } if (candidate instanceof AnnotatedBeanDefinition) { AnnotationConfigUtils.processCommonDefinitionAnnotations((AnnotatedBeanDefinition) candidate); } if (checkCandidate(beanName, candidate)) { BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(candidate, beanName); definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry); beanDefinitions.add(definitionHolder); registerBeanDefinition(definitionHolder, this.registry); } } } return beanDefinitions; }
Example #19
Source File: ClassPathScanningProvider.java From spring-data-generator with MIT License | 5 votes |
@Override protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) { if (classComparator == null) { return false; } boolean isNonRepositoryInterface = !classComparator.getName().equals(beanDefinition.getBeanClassName()); boolean isTopLevelType = !beanDefinition.getMetadata().hasEnclosingClass(); return isNonRepositoryInterface && isTopLevelType; }
Example #20
Source File: DoradoAutoConfiguration.java From dorado with Apache License 2.0 | 5 votes |
private String[] getSpringBootAppScanPackages() { BeanDefinitionRegistry registry = (BeanDefinitionRegistry) applicationContext; Set<String> packages = new HashSet<>(); String[] names = registry.getBeanDefinitionNames(); for (String name : names) { BeanDefinition definition = registry.getBeanDefinition(name); if (definition instanceof AnnotatedBeanDefinition) { AnnotatedBeanDefinition annotatedDefinition = (AnnotatedBeanDefinition) definition; addComponentScanningPackages(packages, annotatedDefinition.getMetadata()); } } return packages.toArray(new String[] {}); }
Example #21
Source File: AnnotationBeanNameGeneratorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void generateBeanNameFromMetaComponentWithNonStringValue() { BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry(); AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentFromNonStringMeta.class); String beanName = this.beanNameGenerator.generateBeanName(bd, registry); assertEquals("annotationBeanNameGeneratorTests.ComponentFromNonStringMeta", beanName); }
Example #22
Source File: BeanMethodMetadataTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void providesBeanMethodBeanDefinition() throws Exception { AnnotationConfigApplicationContext context= new AnnotationConfigApplicationContext(Conf.class); BeanDefinition beanDefinition = context.getBeanDefinition("myBean"); assertThat("should provide AnnotatedBeanDefinition", beanDefinition, instanceOf(AnnotatedBeanDefinition.class)); Map<String, Object> annotationAttributes = ((AnnotatedBeanDefinition) beanDefinition).getFactoryMethodMetadata().getAnnotationAttributes(MyAnnotation.class.getName()); assertThat(annotationAttributes.get("value"), equalTo("test")); context.close(); }
Example #23
Source File: AnnotationBeanNameGeneratorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * @since 4.0.1 * @see https://jira.spring.io/browse/SPR-11360 */ @Test public void generateBeanNameFromComposedControllerAnnotationWithoutName() { BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry(); AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComposedControllerAnnotationWithoutName.class); String beanName = this.beanNameGenerator.generateBeanName(bd, registry); String expectedGeneratedBeanName = this.beanNameGenerator.buildDefaultBeanName(bd); assertEquals(expectedGeneratedBeanName, beanName); }
Example #24
Source File: AnnotationScopeMetadataResolverTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void resolveScopeMetadataShouldReadScopedProxyModeFromAnnotation() { AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithScopedProxy.class); ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd); assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata); assertEquals("request", scopeMetadata.getScopeName()); assertEquals(TARGET_CLASS, scopeMetadata.getScopedProxyMode()); }
Example #25
Source File: AnnotationBeanNameGeneratorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void generateBeanNameWithNamedComponentWhereTheNameIsBlank() { BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry(); AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentWithBlankName.class); String beanName = this.beanNameGenerator.generateBeanName(bd, registry); assertNotNull("The generated beanName must *never* be null.", beanName); assertTrue("The generated beanName must *never* be blank.", StringUtils.hasText(beanName)); String expectedGeneratedBeanName = this.beanNameGenerator.buildDefaultBeanName(bd); assertEquals(expectedGeneratedBeanName, beanName); }
Example #26
Source File: AnnotationBeanNameGeneratorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void generateBeanNameWithDefaultNamedComponent() { BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry(); AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(DefaultNamedComponent.class); String beanName = this.beanNameGenerator.generateBeanName(bd, registry); assertNotNull("The generated beanName must *never* be null.", beanName); assertTrue("The generated beanName must *never* be blank.", StringUtils.hasText(beanName)); assertEquals("thoreau", beanName); }
Example #27
Source File: AnnotationBeanNameGeneratorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void generateBeanNameWithNamedComponent() { BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry(); AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentWithName.class); String beanName = this.beanNameGenerator.generateBeanName(bd, registry); assertNotNull("The generated beanName must *never* be null.", beanName); assertTrue("The generated beanName must *never* be blank.", StringUtils.hasText(beanName)); assertEquals("walden", beanName); }
Example #28
Source File: AnnotationScopeMetadataResolverTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void resolveScopeMetadataShouldNotApplyScopedProxyModeToSingleton() { AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithSingletonScope.class); ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd); assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata); assertEquals(BeanDefinition.SCOPE_SINGLETON, scopeMetadata.getScopeName()); assertEquals(NO, scopeMetadata.getScopedProxyMode()); }
Example #29
Source File: AnnotationBeanDefinitionRegistryPostProcessor.java From spring-context-support with Apache License 2.0 | 5 votes |
private void putPrimaryBeanDefinition(Map<String, AnnotatedBeanDefinition> primaryBeanDefinitions, AnnotatedBeanDefinition annotatedBeanDefinition, String... keys) { if (!ObjectUtils.isEmpty(keys)) { for (String key : keys) { primaryBeanDefinitions.put(key, annotatedBeanDefinition); } } }
Example #30
Source File: FunctionDetectorCondition.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 5 votes |
private static List<String> pruneFunctionBeansForKafkaStreams(List<String> strings, ConditionContext context) { final List<String> prunedList = new ArrayList<>(); for (String key : strings) { final Class<?> classObj = ClassUtils.resolveClassName(((AnnotatedBeanDefinition) context.getBeanFactory().getBeanDefinition(key)) .getMetadata().getClassName(), ClassUtils.getDefaultClassLoader()); try { Method[] methods = classObj.getMethods(); Optional<Method> kafkaStreamMethod = Arrays.stream(methods).filter(m -> m.getName().equals(key)).findFirst(); if (kafkaStreamMethod.isPresent()) { Method method = kafkaStreamMethod.get(); ResolvableType resolvableType = ResolvableType.forMethodReturnType(method, classObj); final Class<?> rawClass = resolvableType.getGeneric(0).getRawClass(); if (rawClass == KStream.class || rawClass == KTable.class || rawClass == GlobalKTable.class) { prunedList.add(key); } } } catch (Exception e) { LOG.error("Function not found: " + key, e); } } return prunedList; }