本文整理汇总了Java中org.springframework.core.type.AnnotationMetadata类的典型用法代码示例。如果您正苦于以下问题:Java AnnotationMetadata类的具体用法?Java AnnotationMetadata怎么用?Java AnnotationMetadata使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AnnotationMetadata类属于org.springframework.core.type包,在下文中一共展示了AnnotationMetadata类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerBeanDefinitions
import org.springframework.core.type.AnnotationMetadata; //导入依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
logger.debug("Searching for mappers annotated with @Mapper");
ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);
try {
if (this.resourceLoader != null) {
scanner.setResourceLoader(this.resourceLoader);
}
List<String> packages = AutoConfigurationPackages.get(this.beanFactory);
if (logger.isDebugEnabled()) {
for (String pkg : packages) {
logger.debug("Using auto-configuration base package '" + pkg + "'");
}
}
scanner.setAnnotationClass(Mapper.class);
scanner.registerFilters();
scanner.doScan(StringUtils.toStringArray(packages));
} catch (IllegalStateException ex) {
logger.debug("Could not determine auto-configuration package, automatic mapper scanning disabled." + ex);
}
}
示例2: getBasePackages
import org.springframework.core.type.AnnotationMetadata; //导入依赖的package包/类
/**
* Gets base packages.
*
* @param importingClassMetadata the importing class metadata
* @return the base packages
*/
protected Set<String> getBasePackages(AnnotationMetadata importingClassMetadata) {
Map<String, Object> attributes = importingClassMetadata
.getAnnotationAttributes(EnableRestyPass.class.getCanonicalName());
Set<String> basePackages = new HashSet<>();
if (StringUtils.hasText((String) attributes.get("value"))) {
basePackages.add((String) attributes.get("value"));
}
for (String pkg : (String[]) attributes.get("basePackages")) {
if (StringUtils.hasText(pkg)) {
basePackages.add(pkg);
}
}
for (Class<?> clazz : (Class[]) attributes.get("basePackageClasses")) {
basePackages.add(ClassUtils.getPackageName(clazz));
}
if (basePackages.isEmpty()) {
basePackages.add(
ClassUtils.getPackageName(importingClassMetadata.getClassName()));
}
return basePackages;
}
示例3: registerBeanDefinitions
import org.springframework.core.type.AnnotationMetadata; //导入依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
BeanDefinitionRegistry registry) {
ComposedTaskProperties properties = composedTaskProperties();
TaskParser taskParser = new TaskParser("bean-registration",
properties.getGraph(), false, true);
Map<String, Integer> taskSuffixMap = getTaskApps(taskParser);
for (String taskName : taskSuffixMap.keySet()) {
//handles the possibility that multiple instances of
// task definition exist in a composed task
for (int taskSuffix = 0; taskSuffixMap.get(taskName) >= taskSuffix; taskSuffix++) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder
.rootBeanDefinition(ComposedTaskRunnerStepFactory.class);
builder.addConstructorArgValue(properties);
builder.addConstructorArgValue(String.format("%s_%s",
taskName, taskSuffix));
builder.addPropertyValue("taskSpecificProps",
getPropertiesForTask(taskName, properties));
builder.addPropertyValue("arguments", properties.getComposedTaskArguments());
registry.registerBeanDefinition(String.format("%s_%s",
taskName, taskSuffix), builder.getBeanDefinition());
}
}
}
开发者ID:spring-cloud-task-app-starters,项目名称:composed-task-runner,代码行数:26,代码来源:StepBeanDefinitionRegistrar.java
示例4: registerBeanDefinitions
import org.springframework.core.type.AnnotationMetadata; //导入依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata metadata,
BeanDefinitionRegistry registry) {
MultiValueMap<String, Object> attributes = metadata
.getAllAnnotationAttributes(
EnableConfigService.class.getName(), false);
Object[] type = attributes == null ? null
: (Object[]) attributes.getFirst("converters");
if (type == null || type.length == 0) {
return;
}
List<Class<?>> types = collectClasses(attributes.get("converters"));
// for (Class<?> type : types) {
// String name = type.getName();
// if (!registry.containsBeanDefinition(name)) {
// registerBeanDefinition(registry, type, name);
// }
// }
registerConverters(registry, types);
}
示例5: registerBeanDefinitions
import org.springframework.core.type.AnnotationMetadata; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
LepServiceProvider scanner = getScanner();
Set<String> basePackages = getBasePackages(importingClassMetadata);
for (String basePackage : basePackages) {
Set<BeanDefinition> candidateComponents = scanner.findCandidateComponents(basePackage);
for (BeanDefinition candidateComponent : candidateComponents) {
if (candidateComponent instanceof AnnotatedBeanDefinition) {
AnnotatedBeanDefinition beanDefinition = (AnnotatedBeanDefinition) candidateComponent;
AnnotationMetadata annotationMetadata = beanDefinition.getMetadata();
Map<String, Object> attributes = annotationMetadata
.getAnnotationAttributes(LepService.class.getCanonicalName());
registerLepService(registry, annotationMetadata, attributes);
}
}
}
}
示例6: getBeanName
import org.springframework.core.type.AnnotationMetadata; //导入依赖的package包/类
private static String getBeanName(AnnotationMetadata annotationMetadata, Map<String, Object> attributes) {
// name & value are aliases
String beanName = (String) attributes.get("value");
if (!StringUtils.isEmpty(beanName)) {
return beanName;
} else {
// generate bean name from class name
String shortName = ClassUtils.getShortName(annotationMetadata.getClassName());
return StringUtils.uncapitalize(shortName);
}
}
示例7: selectImports
import org.springframework.core.type.AnnotationMetadata; //导入依赖的package包/类
/**
* selectImports
* <p>
* Provides a configuration list of additional Import which should be performed to
* implement the applicable configuration.
*
* @param importingClassMetadata Annotations Metadata to use to construct Imports.
* @return String Array of Configuration Imports.
*/
@Override
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
AnnotationAttributes attributes =
AnnotationAttributes.fromMap(
importingClassMetadata.getAnnotationAttributes(EnableYourMicroservice.class.getName(), false));
String environmentType = attributes.getString("environmentType");
LOGGER.info("Using specified EnvironmentType:[{}]", environmentType);
/**
* Create our necessary Imports.
*/
return new String[]{
YourMicroserviceEnvironmentConfiguration.class.getName()
// Add Security Import as Applicable ...
};
}
示例8: findMangoDaoClasses
import org.springframework.core.type.AnnotationMetadata; //导入依赖的package包/类
private List<Class<?>> findMangoDaoClasses(String packages) {
try {
List<Class<?>> daos = new ArrayList<Class<?>>();
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resourcePatternResolver);
for (String locationPattern : getLocationPattern(packages)) {
Resource[] rs = resourcePatternResolver.getResources(locationPattern);
for (Resource r : rs) {
MetadataReader reader = metadataReaderFactory.getMetadataReader(r);
AnnotationMetadata annotationMD = reader.getAnnotationMetadata();
if (annotationMD.hasAnnotation(DB.class.getName())) {
ClassMetadata clazzMD = reader.getClassMetadata();
daos.add(Class.forName(clazzMD.getClassName()));
}
}
}
return daos;
} catch (Exception e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
示例9: determineBeanNameFromAnnotation
import org.springframework.core.type.AnnotationMetadata; //导入依赖的package包/类
/**
* 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;
}
示例10: registerBeanDefinitionForImportedConfigurationClass
import org.springframework.core.type.AnnotationMetadata; //导入依赖的package包/类
/**
* Register the {@link Configuration} class itself as a bean definition.
*/
private void registerBeanDefinitionForImportedConfigurationClass(ConfigurationClass configClass) {
AnnotationMetadata metadata = configClass.getMetadata();
BeanDefinition configBeanDef = new AnnotatedGenericBeanDefinition(metadata);
if (ConfigurationClassUtils.checkConfigurationClassCandidate(configBeanDef, this.metadataReaderFactory)) {
String configBeanName = this.importBeanNameGenerator.generateBeanName(configBeanDef, this.registry);
this.registry.registerBeanDefinition(configBeanName, configBeanDef);
configClass.setBeanName(configBeanName);
if (logger.isDebugEnabled()) {
logger.debug(String.format("Registered bean definition for imported @Configuration class %s", configBeanName));
}
}
else {
this.problemReporter.error(
new InvalidConfigurationImportProblem(metadata.getClassName(), configClass.getResource(), metadata));
}
}
示例11: registerBeanDefinitions
import org.springframework.core.type.AnnotationMetadata; //导入依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
AnnotationAttributes enableMenu = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(EnableMenu.class
.getName(),
false));
if (enableMenu != null) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(DefaultMenuPlugin.class);
AbstractBeanDefinition beanDefinition = builder.getBeanDefinition();
MutablePropertyValues mutablePropertyValues = new MutablePropertyValues();
mutablePropertyValues.add("extensionPointId", enableMenu.getString("extensionPointId"));
mutablePropertyValues.add("pluginId", enableMenu.getString("pluginId"));
mutablePropertyValues.add("menu", toMenu(enableMenu.getAnnotationArray("menu")));
beanDefinition.setPropertyValues(mutablePropertyValues);
registry.registerBeanDefinition("menuPlugin:" + enableMenu.getString("pluginId"), beanDefinition);
}
}
示例12: registerBeanDefinitions
import org.springframework.core.type.AnnotationMetadata; //导入依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {
// Register JPA Datastore (transactional)
if (beanFactory instanceof ListableBeanFactory) {
String[] emfBeanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
(ListableBeanFactory) beanFactory, EntityManagerFactory.class, true, false);
if (emfBeanNames == null || emfBeanNames.length == 0) {
emfBeanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors((ListableBeanFactory) beanFactory,
AbstractEntityManagerFactoryBean.class, true, false);
}
if (emfBeanNames != null && emfBeanNames.length == 1) {
String emfBeanName = (emfBeanNames[0].startsWith("&")) ? emfBeanNames[0].substring(1) : emfBeanNames[0];
JpaDatastoreRegistrar.registerDatastore(registry, null, PrimaryMode.AUTO, emfBeanName, true, false,
beanClassLoader);
}
}
}
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:18,代码来源:JpaDatastoreAutoConfigurationRegistrar.java
示例13: registerBeanDefinitions
import org.springframework.core.type.AnnotationMetadata; //导入依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
logger.debug("Searching for mappers annotated with @Mapper");
ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);
scanner.setMapperProperties(environment);
try {
if (this.resourceLoader != null) {
scanner.setResourceLoader(this.resourceLoader);
}
List<String> packages = AutoConfigurationPackages.get(this.beanFactory);
if (logger.isDebugEnabled()) {
for (String pkg : packages) {
logger.debug("Using auto-configuration base package '{}'", pkg);
}
}
scanner.setAnnotationClass(Mapper.class);
scanner.registerFilters();
scanner.doScan(StringUtils.toStringArray(packages));
} catch (IllegalStateException ex) {
logger.debug("Could not determine auto-configuration package, automatic mapper scanning disabled.", ex);
}
}
示例14: registerBeanDefinitions
import org.springframework.core.type.AnnotationMetadata; //导入依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {
Map<String, Object> attributes = annotationMetadata.getAnnotationAttributes(EnableBeanContext.class.getName());
if (attributes == null) {
return;
}
boolean lookupByType = (boolean) attributes.get("lookupByType");
// check environment
if (environment.containsProperty(EnableBeanContext.LOOKUP_BY_TYPE_PROPERTY_NAME)) {
lookupByType = environment.getProperty(EnableBeanContext.LOOKUP_BY_TYPE_PROPERTY_NAME, Boolean.class);
}
// register post processor
if (!registry.containsBeanDefinition(BEAN_FACTORY_SCOPE_POST_PROCESSOR_NAME)) {
BeanDefinitionBuilder postProcessorBuilder = BeanDefinitionBuilder
.genericBeanDefinition(BeanFactoryScopePostProcessor.class).setDestroyMethodName("unregister")
.addPropertyValue("lookupByType", lookupByType).setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
registry.registerBeanDefinition(BEAN_FACTORY_SCOPE_POST_PROCESSOR_NAME,
postProcessorBuilder.getBeanDefinition());
}
}
示例15: registerBeanDefinitions
import org.springframework.core.type.AnnotationMetadata; //导入依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {
// Single annotation
if (annotationMetadata.isAnnotated(repeatableAnnotation.getName())) {
register(annotationMetadata.getAnnotationAttributes(repeatableAnnotation.getName()), registry, false);
} else if (annotationMetadata.isAnnotated(repeatableAnnotationContainer.getName())) {
// Multiple annotations
Map<String, Object> attributes = annotationMetadata
.getAnnotationAttributes(repeatableAnnotationContainer.getName());
AnnotationAttributes[] repetitions = (AnnotationAttributes[]) attributes.get("value");
if (repetitions != null) {
for (AnnotationAttributes repetition : repetitions) {
register(repetition, registry, true);
}
}
}
}