Java Code Examples for org.springframework.core.type.AnnotationMetadata

The following examples show how to use org.springframework.core.type.AnnotationMetadata. These examples are extracted from open source projects. 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
@SuppressWarnings("unused")
@Override
protected AbstractFunctionExecutionConfigurationSource newAnnotationBasedFunctionExecutionConfigurationSource(
		AnnotationMetadata annotationMetadata) {

	StandardAnnotationMetadata metadata =
		new StandardAnnotationMetadata(getConfiguration(), true);

	return new AnnotationFunctionExecutionConfigurationSource(metadata) {

		@Override
		public Iterable<String> getBasePackages() {
			return AutoConfigurationPackages.get(getBeanFactory());
		}
	};
}
 
Example 2
Source Project: java-technology-stack   Source File: ImportSelectorTests.java    License: MIT License 6 votes vote down vote up
@Test
public void importSelectorsSeparateWithGroup() {
	DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory());
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory);
	context.register(GroupedConfig1.class);
	context.register(GroupedConfig2.class);
	context.refresh();
	InOrder ordered = inOrder(beanFactory);
	ordered.verify(beanFactory).registerBeanDefinition(eq("c"), any());
	ordered.verify(beanFactory).registerBeanDefinition(eq("d"), any());
	assertThat(TestImportGroup.instancesCount.get(), equalTo(1));
	assertThat(TestImportGroup.imports.size(), equalTo(2));
	Iterator<AnnotationMetadata> iterator = TestImportGroup.imports.keySet().iterator();
	assertThat(iterator.next().getClassName(), equalTo(GroupedConfig2.class.getName()));
	assertThat(iterator.next().getClassName(), equalTo(GroupedConfig1.class.getName()));
}
 
Example 3
@Override
protected AnnotationMetadata get(Class<?> source) {
	try {
		ClassLoader classLoader = source.getClassLoader();
		String className = source.getName();
		String resourcePath = ResourceLoader.CLASSPATH_URL_PREFIX
				+ ClassUtils.convertClassNameToResourcePath(className)
				+ ClassUtils.CLASS_FILE_SUFFIX;
		Resource resource = new DefaultResourceLoader().getResource(resourcePath);
		try (InputStream inputStream = new BufferedInputStream(
				resource.getInputStream())) {
			ClassReader classReader = new ClassReader(inputStream);
			AnnotationMetadataReadingVisitor metadata = new AnnotationMetadataReadingVisitor(
					classLoader);
			classReader.accept(metadata, ClassReader.SKIP_DEBUG);
			return metadata;
		}
	}
	catch (Exception ex) {
		throw new IllegalStateException(ex);
	}
}
 
Example 4
/**
 * 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 5
@Override
@SuppressWarnings("deprecation")
public void setImportMetadata(AnnotationMetadata importMetadata) {
	Map<String, Object> attributeMap = importMetadata
			.getAnnotationAttributes(EnableRedisHttpSession.class.getName());
	AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap);
	this.maxInactiveIntervalInSeconds = attributes.getNumber("maxInactiveIntervalInSeconds");
	String redisNamespaceValue = attributes.getString("redisNamespace");
	if (StringUtils.hasText(redisNamespaceValue)) {
		this.redisNamespace = this.embeddedValueResolver.resolveStringValue(redisNamespaceValue);
	}
	FlushMode flushMode = attributes.getEnum("flushMode");
	RedisFlushMode redisFlushMode = attributes.getEnum("redisFlushMode");
	if (flushMode == FlushMode.ON_SAVE && redisFlushMode != RedisFlushMode.ON_SAVE) {
		flushMode = redisFlushMode.getFlushMode();
	}
	this.flushMode = flushMode;
	this.saveMode = attributes.getEnum("saveMode");
	String cleanupCron = attributes.getString("cleanupCron");
	if (StringUtils.hasText(cleanupCron)) {
		this.cleanupCron = cleanupCron;
	}
}
 
Example 6
@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 7
Source Project: onetwo   Source File: RestApiClentRegistrar.java    License: Apache License 2.0 6 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));
		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 8
Source Project: wallride   Source File: WebAdminComponentScanRegistrar.java    License: Apache License 2.0 6 votes vote down vote up
private Set<String> getPackagesToScan(AnnotationMetadata metadata) {
	AnnotationAttributes attributes = AnnotationAttributes
			.fromMap(metadata.getAnnotationAttributes(WebAdminComponentScan.class.getName()));
	String[] value = attributes.getStringArray("value");
	String[] basePackages = attributes.getStringArray("basePackages");
	Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses");
	if (!ObjectUtils.isEmpty(value)) {
		Assert.state(ObjectUtils.isEmpty(basePackages),
				"@WebAdminComponentScan basePackages and value attributes are mutually exclusive");
	}
	Set<String> packagesToScan = new LinkedHashSet<String>();
	packagesToScan.addAll(Arrays.asList(value));
	packagesToScan.addAll(Arrays.asList(basePackages));
	for (Class<?> basePackageClass : basePackageClasses) {
		packagesToScan.add(ClassUtils.getPackageName(basePackageClass));
	}
	if (packagesToScan.isEmpty()) {
		return Collections.singleton(ClassUtils.getPackageName(metadata.getClassName()));
	}
	return packagesToScan;
}
 
Example 9
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 10
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 11
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

    logger.debug("Searching for mappers based with EnhanceMapper.class");
    // 重写扫描实现类
    // 将扫描到的每一个类
    EnhanceClassPathMapperScanner scanner = new EnhanceClassPathMapperScanner(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.setMarkerInterface(EnhanceMapper.class);
        // 通过注解形式扫描
        //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);
    }
}
 
Example 12
public void setImportMetadata(AnnotationMetadata importMetadata) {
    Map<String, Object> enableAttrMap = importMetadata.getAnnotationAttributes(EnableRedisHttpSession.class.getName());
    AnnotationAttributes enableAttrs = AnnotationAttributes.fromMap(enableAttrMap);
    this.maxInactiveIntervalInSeconds = enableAttrs.getNumber("maxInactiveIntervalInSeconds");
    String redisNamespaceValue = enableAttrs.getString("redisNamespace");
    if (StringUtils.hasText(redisNamespaceValue)) {
        this.redisNamespace = this.embeddedValueResolver.resolveStringValue(redisNamespaceValue);
    }

    this.redisFlushMode = enableAttrs.getEnum("redisFlushMode");
}
 
Example 13
@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"));
}
 
Example 14
Source Project: GyJdbc   Source File: BindPointAspectRegistar.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    if (!inited) {
        RootBeanDefinition root = new RootBeanDefinition();
        root.setBeanClass(BindPointAspect.class);
        registry.registerBeanDefinition(BindPointAspect.class.getName(), root);
        inited = true;
    }
}
 
Example 15
Source Project: onetwo   Source File: Simple2RestApiClentRegistrar.java    License: 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));
	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 16
Source Project: spring-analysis-note   Source File: AbstractAsyncConfiguration.java    License: MIT License 5 votes vote down vote up
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
	this.enableAsync = AnnotationAttributes.fromMap(
			importMetadata.getAnnotationAttributes(EnableAsync.class.getName(), false));
	if (this.enableAsync == null) {
		throw new IllegalArgumentException(
				"@EnableAsync is not present on importing class " + importMetadata.getClassName());
	}
}
 
Example 17
Source Project: tx-lcn   Source File: DependenciesImportSelector.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * resolve the spi classes
 *
 * @param importingClassMetadata importingClassMetadata
 * @return spi classes
 */
@Override
@NonNull
public String[] selectImports(@NonNull AnnotationMetadata importingClassMetadata) {
    boolean enabledTxc = Boolean.valueOf(
            Objects.requireNonNull(
                    importingClassMetadata.getAnnotationAttributes(EnableDistributedTransaction.class.getName()))
                    .get("enableTxc").toString());
    List<String> importClasses = new ArrayList<>();
    importClasses.add("com.codingapi.txlcn.txmsg.MessageConfiguration");
    if (enabledTxc) {
        importClasses.add(TxcConfiguration.class.getName());
    }
    return importClasses.toArray(new String[0]);
}
 
Example 18
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry){
    Class beanClass = RabbitmqOfflineInfoHelper.class;
    RootBeanDefinition beanDefinition = new RootBeanDefinition(beanClass);
    String beanName = StringUtils.uncapitalize(beanClass.getSimpleName());
    //在这里可以拿到所有注解的信息,可以根据不同注解来返回不同的class,从而达到开启不同功能的目的
    //通过这种方式可以自定义beanName
    registry.registerBeanDefinition(beanName, beanDefinition);
}
 
Example 19
Source Project: spring-content   Source File: CmisRegistrar.java    License: Apache License 2.0 5 votes vote down vote up
BeanDefinition createTypeDefinition(Class<?> bd, Class<?> rbd, Class<?> sbd, AnnotationMetadata annotationMetadata) {
	BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CmisTypeDefinitionFactoryBean.class);
	builder.getRawBeanDefinition().setSource(annotationMetadata);
	try {
		builder.addPropertyValue("entityClass", bd);
		builder.addPropertyValue("repoClass", rbd);
		builder.addPropertyValue("storeClass", sbd);
	}
	catch (Throwable t) {
	}
	return builder.getBeanDefinition();
}
 
Example 20
Source Project: lams   Source File: AnnotationConfigUtils.java    License: GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
static Set<AnnotationAttributes> attributesForRepeatable(AnnotationMetadata metadata,
		String containerClassName, String annotationClassName) {

	Set<AnnotationAttributes> result = new LinkedHashSet<AnnotationAttributes>();
	addAttributesIfNotNull(result, metadata.getAnnotationAttributes(annotationClassName, false));

	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 Collections.unmodifiableSet(result);
}
 
Example 21
@Override
public String[] selectImports(AnnotationMetadata metadata) {
	MultiValueMap<String,Object> attributes = metadata.getAllAnnotationAttributes(EnableMenu.class.getName(),
																				  false);
	String pluginId = attributes == null ? null : (String) attributes.getFirst("pluginId");

	if (StringUtils.isEmpty(pluginId)) {
		return new String[0];

	}
	return new String[]{MenuPluginBeanRegistrar.class.getName()};
}
 
Example 22
Source Project: java-technology-stack   Source File: MBeanExportConfiguration.java    License: MIT License 5 votes vote down vote up
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
	Map<String, Object> map = importMetadata.getAnnotationAttributes(EnableMBeanExport.class.getName());
	this.enableMBeanExport = AnnotationAttributes.fromMap(map);
	if (this.enableMBeanExport == null) {
		throw new IllegalArgumentException(
				"@EnableMBeanExport is not present on importing class " + importMetadata.getClassName());
	}
}
 
Example 23
Source Project: java-technology-stack   Source File: ConfigurationClassParser.java    License: MIT License 5 votes vote down vote up
@Override
public void removeImportingClass(String importingClass) {
	for (List<AnnotationMetadata> list : this.imports.values()) {
		for (Iterator<AnnotationMetadata> iterator = list.iterator(); iterator.hasNext();) {
			if (iterator.next().getClassName().equals(importingClass)) {
				iterator.remove();
				break;
			}
		}
	}
}
 
Example 24
Source Project: cuba   Source File: WindowConfig.java    License: Apache License 2.0 5 votes vote down vote up
protected void registerScreen(String id, WindowInfo windowInfo) {
    String controllerClassName = windowInfo.getControllerClassName();
    if (controllerClassName != null) {
        MetadataReader classMetadata = loadClassMetadata(controllerClassName);
        AnnotationMetadata annotationMetadata = classMetadata.getAnnotationMetadata();

        registerPrimaryEditor(windowInfo, annotationMetadata);
        registerPrimaryLookup(windowInfo, annotationMetadata);
    }

    screens.put(id, windowInfo);

    registerScreenRoute(id, windowInfo);
}
 
Example 25
Source Project: onetwo   Source File: EnableJFishOauth2Selector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Set<String> doSelect(AnnotationMetadata metadata, AnnotationAttributes attributes) {
	Set<String> classNames = new HashSet<String>();
	
	List<OAuth2Role> roles = Arrays.asList((OAuth2Role[])attributes.get("value"));
	
	classNames.add(PasswordEncoderConfiguration.class.getName());
	
	if(roles.contains(OAuth2Role.AUTHORIZATION_SERVER)){
		classNames.add(AuthorizationServerConfiguration.class.getName());
		classNames.add(Oauth2TokenStoreConfiguration.class.getName());
		classNames.add(OAuth2CustomResultConfiguration.class.getName());
	}
	
	if(roles.contains(OAuth2Role.RESOURCE_SERVER)){
		if(!classNames.contains(Oauth2TokenStoreConfiguration.class.getName())){
			classNames.add(Oauth2TokenStoreConfiguration.class.getName());
		}
		//仍然可通过ResourceServerProps.ENABLED_KEY关掉
		classNames.add(ResourceServerConfiguration.class.getName());
		classNames.add(OAuth2CustomResultConfiguration.class.getName());
		classNames.add(ClientDetailsResolverConfiguration.class.getName());
	}

	if(roles.contains(OAuth2Role.CLIENT_DETAILS_RESOLVER)){
		classNames.add(Oauth2TokenStoreConfiguration.class.getName());
		classNames.add(ClientDetailsResolverConfiguration.class.getName());
	}
	
	return classNames;
}
 
Example 26
@Override
@SuppressWarnings("all")
public void setImportMetadata(AnnotationMetadata importMetadata) {

	if (isAnnotationPresent(importMetadata)) {

		AnnotationAttributes memberNameAttributes = getAnnotationAttributes(importMetadata);

		setMemberName(memberNameAttributes.containsKey("value")
			? memberNameAttributes.getString("value") : null);

		setMemberName(memberNameAttributes.containsKey("name")
			? memberNameAttributes.getString("name") : null);
	}
}
 
Example 27
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry){
    Class beanClass = ActivemqOfflineInfoHelper.class;
    RootBeanDefinition beanDefinition = new RootBeanDefinition(beanClass);
    String beanName = StringUtils.uncapitalize(beanClass.getSimpleName());
    //在这里可以拿到所有注解的信息,可以根据不同注解来返回不同的class,从而达到开启不同功能的目的
    //通过这种方式可以自定义beanName
    registry.registerBeanDefinition(beanName, beanDefinition);
}
 
Example 28
Source Project: teiid-spring-boot   Source File: TeiidPostProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
        BeanDefinitionRegistry registry) {
    if (!registry.containsBeanDefinition(BEAN_NAME)) {
        GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
        beanDefinition.setBeanClass(TeiidPostProcessor.class);
        beanDefinition.setRole(BeanDefinition.ROLE_APPLICATION);
        // We don't need this one to be post processed otherwise it can cause a
        // cascade of bean instantiation that we would rather avoid.
        beanDefinition.setSynthetic(true);
        registry.registerBeanDefinition(BEAN_NAME, beanDefinition);
    }
}
 
Example 29
Source Project: netty-chat   Source File: CustomChatDefinitionRegistrar.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry){
    Class beanClass = CustomOfflineInfoHelper.class;
    RootBeanDefinition beanDefinition = new RootBeanDefinition(beanClass);
    String beanName = StringUtils.uncapitalize(beanClass.getSimpleName());
    //在这里可以拿到所有注解的信息,可以根据不同注解来返回不同的class,从而达到开启不同功能的目的
    //通过这种方式可以自定义beanName
    registry.registerBeanDefinition(beanName, beanDefinition);
}
 
Example 30
@Override
protected void registerContentStoreBeanDefinitions(
		AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

	AnnotationMetadata metadata = new StandardAnnotationMetadata(
			EnableJpaContentAutoConfiguration.class);
	AnnotationAttributes attributes = new AnnotationAttributes(
			metadata.getAnnotationAttributes(this.getAnnotation().getName()));

	String[] basePackages = this.getBasePackages();

	Set<GenericBeanDefinition> definitions = StoreUtils.getStoreCandidates(this.getEnvironment(), this.getResourceLoader(), basePackages, multipleStoreImplementationsDetected(), getIdentifyingTypes());

	this.buildAndRegisterDefinitions(importingClassMetadata, registry, attributes, basePackages, definitions);
}