java类org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition的实例源码

AnnotatedBeanDefinitionReader.java 文件源码 项目:spring 阅读 22 收藏 0 点赞 0 评论 0
public void registerBean(Class<?> annotatedClass, String name,
        @SuppressWarnings("unchecked") Class<? extends Annotation>... qualifiers) {

    AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);
    if (this.conditionEvaluator.shouldSkip(abd.getMetadata())) {
        return;
    }

    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(abd);
    abd.setScope(scopeMetadata.getScopeName());
    String beanName = (name != null ? name : this.beanNameGenerator.generateBeanName(abd, this.registry));
    AnnotationConfigUtils.processCommonDefinitionAnnotations(abd);
    if (qualifiers != null) {
        for (Class<? extends Annotation> qualifier : qualifiers) {
            if (Primary.class == qualifier) {
                abd.setPrimary(true);
            }
            else if (Lazy.class == qualifier) {
                abd.setLazyInit(true);
            }
            else {
                abd.addQualifier(new AutowireCandidateQualifier(qualifier));
            }
        }
    }

    BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(abd, beanName);
    definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
    BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, this.registry);
}
AbstractDevToolsDataSourceAutoConfigurationTests.java 文件源码 项目:spring-boot-concourse 阅读 22 收藏 0 点赞 0 评论 0
@Test
public void emptyFactoryMethodMetadataIgnored() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

    DataSource dataSource = mock(DataSource.class);
    AnnotatedGenericBeanDefinition beanDefinition = new AnnotatedGenericBeanDefinition(
            dataSource.getClass());
    context.registerBeanDefinition("dataSource", beanDefinition);
    context.register(DataSourcePropertiesConfiguration.class);
    context.register(DevToolsDataSourceAutoConfiguration.class);
    context.refresh();
    context.close();
}
SpringInitializer.java 文件源码 项目:Mycat-openEP 阅读 29 收藏 0 点赞 0 评论 0
private static void initAnnotatedConf(GenericApplicationContext context){
    Class componentScanAnnotated=ProcessInfo.getAnnotationInitClass();
    if(componentScanAnnotated!=null){
        AnnotatedGenericBeanDefinition def=new AnnotatedGenericBeanDefinition(ProcessInfo.getAnnotationInitClass());
        AnnotatedBeanDefinitionReader reader=new AnnotatedBeanDefinitionReader(context);
        AnnotationScopeMetadataResolver resolver=new AnnotationScopeMetadataResolver();
        resolver.resolveScopeMetadata(def);
        reader.setScopeMetadataResolver(resolver);
    }
}
ClassPathScanningCandidateComponentProvider.java 文件源码 项目:mybatis-spring-1.2.2 阅读 26 收藏 0 点赞 0 评论 0
private Set<BeanDefinition> findKopBeanComponents(String basePackage){
    boolean debugEnabled = logger.isDebugEnabled();
    Set<BeanDefinition> candidates = new LinkedHashSet<BeanDefinition>();
    List<String> classes = null;
    if(basePackage.contains("com.linda.koala.biz.dao")){
        classes = this.getDaoClasses();
    }else if(basePackage.contains("com.linda.koala.biz")){
        classes = this.getBizClasses();
    }
    if(classes!=null){
        for(String clazz:classes){
            ClassLoader loader = this.getClass().getClassLoader();
            try {
                Class<?> class1 = loader.loadClass(clazz);
                if(class1!=null){

                    AnnotatedGenericBeanDefinition beanDefinition = new AnnotatedGenericBeanDefinition(class1);
                    if (isCandidateComponent(beanDefinition)) {
                        if (debugEnabled) {
                            logger.debug("Identified candidate component class: " + clazz);
                        }
                        candidates.add(beanDefinition);
                    }
                    else {
                        if (debugEnabled) {
                            logger.debug("Ignored because not a concrete top-level class: " +clazz);
                        }
                    }
                }
            } catch (ClassNotFoundException e) {
                throw new BeanDefinitionStoreException("Failed to read candidate component class: " + clazz, e);
            }
        }
    }
    return candidates;
}
RouteRegistrar.java 文件源码 项目:xsf 阅读 20 收藏 0 点赞 0 评论 0
/**
 * loadClass: Loads the route class into the bean defn registry.
 * @param bdr
 * @param className
 */
private void loadClass(BeanDefinitionRegistry bdr, String className) {

    try {
        // try using the class loader to load the given route class
        Class<?> clazz = Class.forName(className);

        // define it in the registry under it's own class name.
        bdr.registerBeanDefinition(className, new AnnotatedGenericBeanDefinition(clazz));
    } catch (ClassNotFoundException e) {
        _logger.error("XSF Route Registrator could not locate class="+className, e);
    }
}
AnnotatedBeanDefinitionReader.java 文件源码 项目:class-guard 阅读 23 收藏 0 点赞 0 评论 0
public void registerBean(Class<?> annotatedClass, String name, Class<? extends Annotation>... qualifiers) {
    AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);
    AnnotationMetadata metadata = abd.getMetadata();
    if (metadata.isAnnotated(Profile.class.getName())) {
        AnnotationAttributes profile = MetadataUtils.attributesFor(metadata, Profile.class);
        if (!this.environment.acceptsProfiles(profile.getStringArray("value"))) {
            return;
        }
    }
    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(abd);
    abd.setScope(scopeMetadata.getScopeName());
    String beanName = (name != null ? name : this.beanNameGenerator.generateBeanName(abd, this.registry));
    AnnotationConfigUtils.processCommonDefinitionAnnotations(abd);
    if (qualifiers != null) {
        for (Class<? extends Annotation> qualifier : qualifiers) {
            if (Primary.class.equals(qualifier)) {
                abd.setPrimary(true);
            }
            else if (Lazy.class.equals(qualifier)) {
                abd.setLazyInit(true);
            }
            else {
                abd.addQualifier(new AutowireCandidateQualifier(qualifier));
            }
        }
    }
    BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(abd, beanName);
    definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
    BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, this.registry);
}
AnnotationScopeMetadataResolverTests.java 文件源码 项目:class-guard 阅读 38 收藏 0 点赞 0 评论 0
@Test
public void testThatResolveScopeMetadataDoesNotApplyScopedProxyModeToASingleton() {
    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(ScopedProxyMode.NO, scopeMetadata.getScopedProxyMode());
}
AnnotationScopeMetadataResolverTests.java 文件源码 项目:class-guard 阅读 28 收藏 0 点赞 0 评论 0
@Test
public void testThatResolveScopeMetadataDoesApplyScopedProxyModeToAPrototype() {
    this.scopeMetadataResolver = new AnnotationScopeMetadataResolver(ScopedProxyMode.INTERFACES);
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithPrototypeScope.class);
    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
    assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
    assertEquals(BeanDefinition.SCOPE_PROTOTYPE, scopeMetadata.getScopeName());
    assertEquals(ScopedProxyMode.INTERFACES, scopeMetadata.getScopedProxyMode());
}
AnnotationScopeMetadataResolverTests.java 文件源码 项目:class-guard 阅读 22 收藏 0 点赞 0 评论 0
@Test
public void testThatResolveScopeMetadataDoesReadScopedProxyModeFromTheAnnotation() {
    this.scopeMetadataResolver = new AnnotationScopeMetadataResolver();
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithScopedProxy.class);
    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
    assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
    assertEquals("request", scopeMetadata.getScopeName());
    assertEquals(ScopedProxyMode.TARGET_CLASS, scopeMetadata.getScopedProxyMode());
}
AnnotationScopeMetadataResolverTests.java 文件源码 项目:class-guard 阅读 19 收藏 0 点赞 0 评论 0
@Test
public void testCustomRequestScope() {
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithCustomRequestScope.class);
    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
    assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
    assertEquals("request", scopeMetadata.getScopeName());
    assertEquals(ScopedProxyMode.NO, scopeMetadata.getScopedProxyMode());
}


问题


面经


文章

微信
公众号

扫码关注公众号