org.springframework.core.annotation.AnnotationAttributes Java Examples

The following examples show how to use org.springframework.core.annotation.AnnotationAttributes. 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: MvcInterceptorManager.java    From onetwo with Apache License 2.0 6 votes vote down vote up
/***
 * 直接查找Interceptor
 * @author wayshall
 * @param hm
 * @return
 */
final protected Collection<AnnotationAttributes> findInterceptorAnnotationAttrsList(HandlerMethod hm){
	Set<Interceptor> inters = AnnotatedElementUtils.getMergedRepeatableAnnotations(hm.getMethod(), Interceptor.class);
	if(LangUtils.isEmpty(inters)){
		inters = AnnotatedElementUtils.getMergedRepeatableAnnotations(hm.getBeanType(), Interceptor.class);
	}
	if(LangUtils.isEmpty(inters)){
		return Collections.emptyList();
	}
	Collection<AnnotationAttributes> attrs = inters.stream()
													.map(inter->org.springframework.core.annotation.AnnotationUtils.getAnnotationAttributes(null, inter))
													.collect(Collectors.toSet());
	boolean hasDisabledFlag = attrs.stream()
									.anyMatch(attr->asMvcInterceptorMeta(attr).getInterceptorType()==DisableMvcInterceptor.class);
	if(hasDisabledFlag){
		return Collections.emptyList();
	}
	return attrs;
}
 
Example #2
Source File: AdviceModeImportSelector.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * This implementation resolves the type of annotation from generic metadata and
 * validates that (a) the annotation is in fact present on the importing
 * {@code @Configuration} class and (b) that the given annotation has an
 * {@linkplain #getAdviceModeAttributeName() advice mode attribute} of type
 * {@link AdviceMode}.
 * <p>The {@link #selectImports(AdviceMode)} method is then invoked, allowing the
 * concrete implementation to choose imports in a safe and convenient fashion.
 * @throws IllegalArgumentException if expected annotation {@code A} is not present
 * on the importing {@code @Configuration} class or if {@link #selectImports(AdviceMode)}
 * returns {@code null}
 */
@Override
public final String[] selectImports(AnnotationMetadata importingClassMetadata) {
	Class<?> annoType = GenericTypeResolver.resolveTypeArgument(getClass(), AdviceModeImportSelector.class);
	AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(importingClassMetadata, annoType);
	if (attributes == null) {
		throw new IllegalArgumentException(String.format(
			"@%s is not present on importing class '%s' as expected",
			annoType.getSimpleName(), importingClassMetadata.getClassName()));
	}

	AdviceMode adviceMode = attributes.getEnum(this.getAdviceModeAttributeName());
	String[] imports = selectImports(adviceMode);
	if (imports == null) {
		throw new IllegalArgumentException(String.format("Unknown AdviceMode: '%s'", adviceMode));
	}
	return imports;
}
 
Example #3
Source File: OnMissingPropertyCondition.java    From spring-boot-data-geode with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private <T extends Collection<AnnotationAttributes>> T toAnnotationAttributesFromMultiValueMap(
		MultiValueMap<String, Object> map) {

	List<AnnotationAttributes> annotationAttributesList = new ArrayList<>();

	map.forEach((key, value) -> {
		for (int index = 0, size = value.size(); index < size; index++) {

			AnnotationAttributes annotationAttributes =
				resolveAnnotationAttributes(annotationAttributesList, index);

			annotationAttributes.put(key, value.get(index));
		}
	});

	return (T) annotationAttributesList;
}
 
Example #4
Source File: ContextRegionConfigurationRegistrar.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
		BeanDefinitionRegistry registry) {
	AnnotationAttributes annotationAttributes = AnnotationAttributes
			.fromMap(importingClassMetadata.getAnnotationAttributes(
					EnableContextRegion.class.getName(), false));
	Assert.notNull(annotationAttributes,
			"@EnableRegionProvider is not present on importing class "
					+ importingClassMetadata.getClassName());

	boolean autoDetect = annotationAttributes.getBoolean("autoDetect");
	boolean useDefaultAwsRegionChain = annotationAttributes
			.getBoolean("useDefaultAwsRegionChain");
	String configuredRegion = annotationAttributes.getString("region");

	registerRegionProvider(registry, autoDetect, useDefaultAwsRegionChain,
			configuredRegion);
}
 
Example #5
Source File: GRpcApiRegister.java    From faster-framework-project with Apache License 2.0 6 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(GRpcServerScan.class.getCanonicalName()));
    if (annotationAttributes == null) {
        log.warn("GrpcScan was not found.Please check your configuration.");
        return;
    }
    ClassPathBeanDefinitionScanner classPathGrpcApiScanner = new ClassPathBeanDefinitionScanner(registry, false);
    classPathGrpcApiScanner.setResourceLoader(this.resourceLoader);
    classPathGrpcApiScanner.addIncludeFilter(new AnnotationTypeFilter(GRpcApi.class));
    List<String> basePackages = AutoConfigurationPackages.get(this.beanFactory);
    for (String pkg : annotationAttributes.getStringArray("basePackages")) {
        if (StringUtils.hasText(pkg)) {
            basePackages.add(pkg);
        }
    }
    classPathGrpcApiScanner.scan(StringUtils.toStringArray(basePackages));
}
 
Example #6
Source File: AspectJAutoProxyRegistrar.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Register, escalate, and configure the AspectJ auto proxy creator based on the value
 * of the @{@link EnableAspectJAutoProxy#proxyTargetClass()} attribute on the importing
 * {@code @Configuration} class.
 */
@Override
public void registerBeanDefinitions(
		AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

	AopConfigUtils.registerAspectJAnnotationAutoProxyCreatorIfNecessary(registry);

	AnnotationAttributes enableAspectJAutoProxy =
			AnnotationConfigUtils.attributesFor(importingClassMetadata, EnableAspectJAutoProxy.class);
	if (enableAspectJAutoProxy.getBoolean("proxyTargetClass")) {
		AopConfigUtils.forceAutoProxyCreatorToUseClassProxying(registry);
	}
	if (enableAspectJAutoProxy.getBoolean("exposeProxy")) {
		AopConfigUtils.forceAutoProxyCreatorToExposeProxy(registry);
	}
}
 
Example #7
Source File: ProducerRegistrar.java    From easy-rabbitmq with Apache License 2.0 6 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata metadata,
    BeanDefinitionRegistry registry) {

  AnnotationAttributes attributes =
      AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(RqueueScan.class.getName()));
  if (attributes == null) {
    log.warn("No @RqueueScan was found");
    return;
  }

  String[] basePackages = attributes.getStringArray("value");
  String basePackage = metadata.getClassName()
      .substring(0, metadata.getClassName().lastIndexOf("."));
  if (basePackages.length == 0) {
    basePackages = new String[]{basePackage};
  } else {
    basePackages = Arrays.copyOf(basePackages, basePackages.length + 1);
    basePackages[basePackages.length - 1] = basePackage;
  }

  ProducerScanner scanner = new ProducerScanner(registry);
  scanner.setResourceLoader(resourceLoader);
  scanner.scan(basePackages);
}
 
Example #8
Source File: AnnotationConfigUtils.java    From java-technology-stack with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
static Set<AnnotationAttributes> attributesForRepeatable(
		AnnotationMetadata metadata, String containerClassName, String annotationClassName) {

	Set<AnnotationAttributes> result = new LinkedHashSet<>();

	// Direct annotation present?
	addAttributesIfNotNull(result, metadata.getAnnotationAttributes(annotationClassName, false));

	// Container annotation present?
	Map<String, Object> container = metadata.getAnnotationAttributes(containerClassName, false);
	if (container != null && container.containsKey("value")) {
		for (Map<String, Object> containedAttributes : (Map<String, Object>[]) container.get("value")) {
			addAttributesIfNotNull(result, containedAttributes);
		}
	}

	// Return merged result
	return Collections.unmodifiableSet(result);
}
 
Example #9
Source File: GRpcClientRegister.java    From faster-framework-project with Apache License 2.0 6 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(GRpcClientScan.class.getCanonicalName()));
    if (annotationAttributes == null) {
        log.warn("GrpcScan was not found.Please check your configuration.");
        return;
    }
    ClassPathGRpcServiceScanner classPathGrpcServiceScanner = new ClassPathGRpcServiceScanner(registry, beanFactory);
    classPathGrpcServiceScanner.setResourceLoader(this.resourceLoader);
    classPathGrpcServiceScanner.addIncludeFilter(new AnnotationTypeFilter(GRpcService.class));
    List<String> basePackages = AutoConfigurationPackages.get(this.beanFactory);
    for (String pkg : annotationAttributes.getStringArray("basePackages")) {
        if (StringUtils.hasText(pkg)) {
            basePackages.add(pkg);
        }
    }
    classPathGrpcServiceScanner.doScan(StringUtils.toStringArray(basePackages));
}
 
Example #10
Source File: MBeanExportConfiguration.java    From java-technology-stack with MIT License 6 votes vote down vote up
private void setupServer(AnnotationMBeanExporter exporter, AnnotationAttributes enableMBeanExport) {
	String server = enableMBeanExport.getString("server");
	if (StringUtils.hasLength(server) && this.environment != null) {
		server = this.environment.resolvePlaceholders(server);
	}
	if (StringUtils.hasText(server)) {
		Assert.state(this.beanFactory != null, "No BeanFactory set");
		exporter.setServer(this.beanFactory.getBean(server, MBeanServer.class));
	}
	else {
		SpecificPlatform specificPlatform = SpecificPlatform.get();
		if (specificPlatform != null) {
			MBeanServer mbeanServer = specificPlatform.getMBeanServer();
			if (mbeanServer != null) {
				exporter.setServer(mbeanServer);
			}
		}
	}
}
 
Example #11
Source File: AnnotationScopeMetadataResolver.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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.getAliasedString("value", this.scopeAnnotationType, definition.getSource()));
			ScopedProxyMode proxyMode = attributes.getEnum("proxyMode");
			if (proxyMode == null || proxyMode == ScopedProxyMode.DEFAULT) {
				proxyMode = this.defaultProxyMode;
			}
			metadata.setScopedProxyMode(proxyMode);
		}
	}
	return metadata;
}
 
Example #12
Source File: AspectJAutoProxyRegistrar.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Register, escalate, and configure the AspectJ auto proxy creator based on the value
 * of the @{@link EnableAspectJAutoProxy#proxyTargetClass()} attribute on the importing
 * {@code @Configuration} class.
 */
@Override
public void registerBeanDefinitions(
		AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

	AopConfigUtils.registerAspectJAnnotationAutoProxyCreatorIfNecessary(registry);

	AnnotationAttributes enableAspectJAutoProxy =
			AnnotationConfigUtils.attributesFor(importingClassMetadata, EnableAspectJAutoProxy.class);
	if (enableAspectJAutoProxy != null) {
		if (enableAspectJAutoProxy.getBoolean("proxyTargetClass")) {
			AopConfigUtils.forceAutoProxyCreatorToUseClassProxying(registry);
		}
		if (enableAspectJAutoProxy.getBoolean("exposeProxy")) {
			AopConfigUtils.forceAutoProxyCreatorToExposeProxy(registry);
		}
	}
}
 
Example #13
Source File: BeanAnnotationHelper.java    From java-technology-stack with MIT License 6 votes vote down vote up
public static String determineBeanNameFor(Method beanMethod) {
	String beanName = beanNameCache.get(beanMethod);
	if (beanName == null) {
		// By default, the bean name is the name of the @Bean-annotated method
		beanName = beanMethod.getName();
		// Check to see if the user has explicitly set a custom bean name...
		AnnotationAttributes bean =
				AnnotatedElementUtils.findMergedAnnotationAttributes(beanMethod, Bean.class, false, false);
		if (bean != null) {
			String[] names = bean.getStringArray("name");
			if (names.length > 0) {
				beanName = names[0];
			}
		}
		beanNameCache.put(beanMethod, beanName);
	}
	return beanName;
}
 
Example #14
Source File: EnableJFishCloudExtensionSelector.java    From onetwo with Apache License 2.0 6 votes vote down vote up
@Override
protected List<String> doSelect(AnnotationMetadata metadata, AnnotationAttributes attributes) {
	List<String> classNames = new ArrayList<String>();
	
	classNames.add(BootCloudConfigration.class.getName());
	classNames.add(AuthEnvsConfiguration.class.getName());
	classNames.add(ErrorHandleConfiguration.class.getName());
	classNames.add(AccessLogConfiguration.class.getName());
	classNames.add(GraceKillConfiguration.class.getName());
	
	classNames.add(CornerFeignConfiguration.class.getName());
	
	classNames.add(CanaryConfiguration.class.getName());
	
	classNames.add(ConfigClientConfiguration.class.getName());
	
	//sleuth
	classNames.add(SleuthConfiguration.class.getName());
	
	classNames.add(CloudManagementConfiguration.class.getName());
	
	return classNames;
}
 
Example #15
Source File: ConfigurationTypeRegistrar.java    From conf4j with MIT License 6 votes vote down vote up
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 #16
Source File: AnnotationBeanNameGenerator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #17
Source File: EventSourceBeanRegistrar.java    From synapse with Apache License 2.0 6 votes vote down vote up
@Override
protected void registerBeanDefinitions(final String channelName,
                                       final String beanName,
                                       final AnnotationAttributes annotationAttributes,
                                       final BeanDefinitionRegistry registry) {
    final Class<? extends MessageLog> channelSelector = annotationAttributes.getClass("selector");
    final String messageLogBeanName = Objects.toString(
            emptyToNull(annotationAttributes.getString("messageLogReceiverEndpoint")),
            beanNameForMessageLogReceiverEndpoint(channelName));

    if (!registry.containsBeanDefinition(messageLogBeanName)) {
        registerMessageLogBeanDefinition(registry, messageLogBeanName, channelName, channelSelector);
    } else {
        throw new BeanCreationException(messageLogBeanName, format("MessageLogReceiverEndpoint %s is already registered.", messageLogBeanName));
    }
    if (!registry.containsBeanDefinition(beanName)) {
        registerEventSourceBeanDefinition(registry, beanName, messageLogBeanName, channelName, channelSelector);
    } else {
        throw new BeanCreationException(beanName, format("EventSource %s is already registered.", beanName));
    }
}
 
Example #18
Source File: OverriddenMetaAnnotationAttributesTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void overriddenContextConfigurationValue() throws Exception {
	Class<?> declaringClass = OverriddenMetaValueConfigTestCase.class;
	AnnotationDescriptor<ContextConfiguration> descriptor = findAnnotationDescriptor(declaringClass,
		ContextConfiguration.class);
	assertNotNull(descriptor);
	assertEquals(declaringClass, descriptor.getRootDeclaringClass());
	assertEquals(MetaValueConfig.class, descriptor.getComposedAnnotationType());
	assertEquals(ContextConfiguration.class, descriptor.getAnnotationType());
	assertNotNull(descriptor.getComposedAnnotation());
	assertEquals(MetaValueConfig.class, descriptor.getComposedAnnotationType());

	// direct access to annotation value:
	assertArrayEquals(new String[] { "foo.xml" }, descriptor.getAnnotation().value());

	// overridden attribute:
	AnnotationAttributes attributes = descriptor.getAnnotationAttributes();

	// NOTE: we would like to be able to override the 'value' attribute; however,
	// Spring currently does not allow overrides for the 'value' attribute.
	// See SPR-11393 for related discussions.
	assertArrayEquals(new String[] { "foo.xml" }, attributes.getStringArray("value"));
}
 
Example #19
Source File: AnnotationMetadataHelper.java    From onetwo with Apache License 2.0 5 votes vote down vote up
public AnnotationMetadataHelper(AnnotationMetadata classMetadata, Class<?> annotationType) {
		super();
		this.importingClassMetadata = classMetadata;
//		this.annotationType = annotationType;
		
		if (classMetadata!=null) {
			AnnotationAttributes attributes = SpringUtils.getAnnotationAttributes(classMetadata, annotationType);
			if (attributes == null) {
				throw new IllegalArgumentException(String.format("@%s is not present on importing class '%s' as expected", annotationType.getSimpleName(), classMetadata.getClassName()));
			}
			this.attributes = attributes;
		}
	}
 
Example #20
Source File: RateLimiterAnnotationParser.java    From Limiter with Apache License 2.0 5 votes vote down vote up
@Override
public LimitedResource<RateLimiter> parseLimiterAnnotation(AnnotationAttributes attributes) {
    return new RateLimiterResource(getKey(attributes),
            getArgumentInjectors(attributes),
            getFallback(attributes),
            getErrorHandler(attributes),
            getLimiter(attributes),
            (double) attributes.getNumber("rate"),
            (long) attributes.getNumber("capacity")
    );
}
 
Example #21
Source File: JtaTransactionAnnotationParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public TransactionAttribute parseTransactionAnnotation(AnnotatedElement ae) {
	AnnotationAttributes attributes =
			AnnotatedElementUtils.getMergedAnnotationAttributes(ae, javax.transaction.Transactional.class);
	if (attributes != null) {
		return parseTransactionAnnotation(attributes);
	}
	else {
		return null;
	}
}
 
Example #22
Source File: RecursiveAnnotationArrayVisitor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public AnnotationVisitor visitAnnotation(String attributeName, String asmTypeDescriptor) {
	String annotationType = Type.getType(asmTypeDescriptor).getClassName();
	AnnotationAttributes nestedAttributes = new AnnotationAttributes();
	this.allNestedAttributes.add(nestedAttributes);
	return new RecursiveAnnotationAttributesVisitor(annotationType, nestedAttributes, this.classLoader);
}
 
Example #23
Source File: MethodMetadataReadingVisitor.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
@Nullable
public AnnotationAttributes getAnnotationAttributes(String annotationName, boolean classValuesAsString) {
	AnnotationAttributes raw = AnnotationReadingVisitorUtils.getMergedAnnotationAttributes(
			this.attributesMap, this.metaAnnotationMap, annotationName);
	if (raw == null) {
		return null;
	}
	return AnnotationReadingVisitorUtils.convertClassValues(
			"method '" + getMethodName() + "'", this.classLoader, raw, classValuesAsString);
}
 
Example #24
Source File: AnnotationAttributesReadingVisitor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public AnnotationAttributesReadingVisitor(String annotationType,
		MultiValueMap<String, AnnotationAttributes> attributesMap, Map<String, Set<String>> metaAnnotationMap,
		ClassLoader classLoader) {

	super(annotationType, new AnnotationAttributes(annotationType, classLoader), classLoader);
	this.attributesMap = attributesMap;
	this.metaAnnotationMap = metaAnnotationMap;
}
 
Example #25
Source File: GeneircApiClentRegistrar.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@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 #26
Source File: AutowiredAnnotationBeanPostProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private AnnotationAttributes findAutowiredAnnotation(AccessibleObject ao) {
	if (ao.getAnnotations().length > 0) {
		for (Class<? extends Annotation> type : this.autowiredAnnotationTypes) {
			AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(ao, type);
			if (attributes != null) {
				return attributes;
			}
		}
	}
	return null;
}
 
Example #27
Source File: FeignClientsRegistrar.java    From spring-cloud-openfeign with Apache License 2.0 5 votes vote down vote up
private void validate(Map<String, Object> attributes) {
	AnnotationAttributes annotation = AnnotationAttributes.fromMap(attributes);
	// This blows up if an aliased property is overspecified
	// FIXME annotation.getAliasedString("name", FeignClient.class, null);
	validateFallback(annotation.getClass("fallback"));
	validateFallbackFactory(annotation.getClass("fallbackFactory"));
}
 
Example #28
Source File: QualifierAnnotationAutowireCandidateResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Extract the value attribute from the given annotation.
 * @since 4.3
 */
protected Object extractValue(AnnotationAttributes attr) {
	Object value = attr.get(AnnotationUtils.VALUE);
	if (value == null) {
		throw new IllegalStateException("Value annotation must have a value attribute");
	}
	return value;
}
 
Example #29
Source File: SpringFactoryImportSelector.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Override
public String[] selectImports(AnnotationMetadata metadata) {
	if (!isEnabled()) {
		return new String[0];
	}
	AnnotationAttributes attributes = AnnotationAttributes.fromMap(
			metadata.getAnnotationAttributes(this.annotationClass.getName(), true));

	Assert.notNull(attributes, "No " + getSimpleName() + " attributes found. Is "
			+ metadata.getClassName() + " annotated with @" + getSimpleName() + "?");

	// Find all possible auto configuration classes, filtering duplicates
	List<String> factories = new ArrayList<>(new LinkedHashSet<>(SpringFactoriesLoader
			.loadFactoryNames(this.annotationClass, this.beanClassLoader)));

	if (factories.isEmpty() && !hasDefaultFactory()) {
		throw new IllegalStateException("Annotation @" + getSimpleName()
				+ " found, but there are no implementations. Did you forget to include a starter?");
	}

	if (factories.size() > 1) {
		// there should only ever be one DiscoveryClient, but there might be more than
		// one factory
		this.log.warn("More than one implementation " + "of @" + getSimpleName()
				+ " (now relying on @Conditionals to pick one): " + factories);
	}

	return factories.toArray(new String[factories.size()]);
}
 
Example #30
Source File: ContextInstanceDataConfiguration.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
		BeanDefinitionRegistry registry) {
	AnnotationAttributes annotationAttributes = AnnotationAttributes
			.fromMap(importingClassMetadata.getAnnotationAttributes(
					EnableContextInstanceData.class.getName(), false));
	Assert.notNull(annotationAttributes,
			"@EnableContextInstanceData is not present on importing class "
					+ importingClassMetadata.getClassName());
	registerInstanceDataPropertySource(registry,
			annotationAttributes.getString("valueSeparator"),
			annotationAttributes.getString("attributeSeparator"));
}