org.springframework.boot.autoconfigure.AutoConfigurationPackages源码实例Demo

类org.springframework.boot.autoconfigure.AutoConfigurationPackages源码实例Demo

下面列出了org.springframework.boot.autoconfigure.AutoConfigurationPackages 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
    log.debug("Searching for mappers annotated with @Mapper");

    ClassPathMapperScanner scanner = new ClassPathMapperScanner(beanDefinitionRegistry);
    try {
        if (this.applicationContext != null) {
            scanner.setResourceLoader(this.applicationContext);
        }
        List<String> packages = AutoConfigurationPackages.get(this.applicationContext);
        scanner.setAnnotationClass(Mapper.class);
        scanner.registerFilters();
        scanner.doScan(StringUtils.toStringArray(packages));
    } catch (IllegalStateException ex) {
        log.debug("Could not determine auto-configuration package, automatic mapper scanning disabled.", ex);
    }
}
 
源代码2 项目: AsyncDao   文件: MapperScannerConfigurer.java
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    log.debug("Searching for mappers annotated with @Mapper");
    ClassPathMapperScanner scanner = new ClassPathMapperScanner((BeanDefinitionRegistry) beanFactory);
    try {
        if (this.applicationContext != null) {
            scanner.setResourceLoader(applicationContext);
        }
        List<String> packages = AutoConfigurationPackages.get(beanFactory);
        scanner.setAnnotationClass(Mapper.class);
        scanner.registerFilters();
        scanner.doScan(StringUtils.toStringArray(packages));
    } catch (IllegalStateException ex) {
        log.debug("Could not determine auto-configuration package, automatic mapper scanning disabled.", ex);
    }
}
 
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    log.debug("Searching for mappers annotated with @Mapper");
    ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);
    try {
        if (this.resourceLoader != null) {
            scanner.setResourceLoader(this.resourceLoader);
        }
        String[] packages;
        Environment env = beanFactory.getBean(Environment.class);
        String basePackages = env.getProperty("async.dao.basePackages");
        if (StringUtils.isEmpty(basePackages)) {
            packages = StringUtils.toStringArray(AutoConfigurationPackages.get(this.beanFactory));
        } else {
            packages = basePackages.split(",");
        }
        scanner.setAnnotationClass(Mapper.class);
        scanner.registerFilters();
        scanner.doScan(packages);
    } catch (IllegalStateException ex) {
        log.debug("Could not determine auto-configuration package, automatic mapper scanning disabled.", ex);
    }
}
 
@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));
}
 
@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));
}
 
@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);
    }
}
 
@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);
    }
}
 
private void createClassPathMapperScanner(BeanDefinitionRegistry registry, String prefixName) {
  ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);

  try {
    if (this.resourceLoader != null) {
      scanner.setResourceLoader(this.resourceLoader);
    }

    List<String> packages = AutoConfigurationPackages.get(beanFactory);
    packages.forEach(pkg -> log.info("Using auto-configuration base package '{}'", pkg));

    scanner.setAnnotationClass(Mapper.class);
    scanner.setSqlSessionFactoryBeanName(prefixName + "SessionFactory");
    scanner.registerFilters();
    scanner.doScan(StringUtils.toStringArray(packages));
  } catch (IllegalStateException ex) {
    log.info("Could not determine auto-configuration package", ex);
  }
}
 
@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());
		}
	};
}
 
@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);
    }
}
 
@Override
public void registerBeanDefinitions(AnnotationMetadata metadata,
	BeanDefinitionRegistry registry) {
	AnnotationAttributes attributes = AnnotationAttributes
		.fromMap(metadata.getAnnotationAttributes(
			TestAutoConfigurationPackage.class.getName(), true));
	AutoConfigurationPackages.register(registry,
		ClassUtils.getPackageName(attributes.getString("value")));
}
 
@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);
    }
}
 
/**
 * 开启上报节点触发器列表线程
 */
private void startHeartSync() {
    // 使用配置文件配置的路径
    String jobBasePackage = jobNodeProperties.getJobBasePackage();
    // 如果并未配置,则使用springboot默认扫描的package
    if (StringUtils.isEmpty(jobBasePackage)) {
        jobBasePackage = AutoConfigurationPackages.get(beanFactory).get(0);
    }
    // 开启心跳检查,每隔5秒执行同步一次
    JobThread.scheduleWithFixedDelay(new HeartSyncRunnable(heartSyncService, jobNodeProperties, jobBasePackage), jobNodeProperties.getSendHeartInitialDelay(), jobNodeProperties.getSendHeartSyncTime());
}
 
源代码14 项目: springdoc-openapi   文件: OpenAPIBuilder.java
/**
 * Gets open api definition.
 *
 * @return the open api definition
 */
private Optional<OpenAPIDefinition> getOpenAPIDefinition() {
	// Look for OpenAPIDefinition in a spring managed bean
	Map<String, Object> openAPIDefinitionMap = context.getBeansWithAnnotation(OpenAPIDefinition.class);
	OpenAPIDefinition apiDef = null;
	if (openAPIDefinitionMap.size() > 1)
		LOGGER.warn(
				"found more than one OpenAPIDefinition class. springdoc-openapi will be using the first one found.");
	if (openAPIDefinitionMap.size() > 0) {
		Map.Entry<String, Object> entry = openAPIDefinitionMap.entrySet().iterator().next();
		Class<?> objClz = entry.getValue().getClass();
		apiDef = AnnotatedElementUtils.findMergedAnnotation(objClz, OpenAPIDefinition.class);
	}

	// Look for OpenAPIDefinition in the spring classpath
	else {
		ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(
				false);
		scanner.addIncludeFilter(new AnnotationTypeFilter(OpenAPIDefinition.class));
		if (AutoConfigurationPackages.has(context)) {
			List<String> packagesToScan = AutoConfigurationPackages.get(context);
			apiDef = getApiDefClass(scanner, packagesToScan);
		}

	}
	return Optional.ofNullable(apiDef);
}
 
源代码15 项目: seata-samples   文件: MybatisPlusAutoConfig.java
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    MybatisPlusAutoConfig.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 (MybatisPlusAutoConfig.logger.isDebugEnabled()) {
            Iterator iterator = packages.iterator();

            while(iterator.hasNext()) {
                String pkg = (String)iterator.next();
                MybatisPlusAutoConfig.logger.debug("Using auto-configuration base package '" + pkg + "'");
            }
        }

        scanner.setAnnotationClass(Mapper.class);
        scanner.registerFilters();
        scanner.doScan(StringUtils.toStringArray(packages));
    } catch (IllegalStateException var7) {
        MybatisPlusAutoConfig.logger.debug("Could not determine auto-configuration package, automatic mapper scanning disabled." + var7);
    }

}
 
源代码16 项目: seata-samples   文件: MybatisPlusAutoConfig.java
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    MybatisPlusAutoConfig.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 (MybatisPlusAutoConfig.logger.isDebugEnabled()) {
            Iterator iterator = packages.iterator();

            while(iterator.hasNext()) {
                String pkg = (String)iterator.next();
                MybatisPlusAutoConfig.logger.debug("Using auto-configuration base package '" + pkg + "'");
            }
        }

        scanner.setAnnotationClass(Mapper.class);
        scanner.registerFilters();
        scanner.doScan(StringUtils.toStringArray(packages));
    } catch (IllegalStateException var7) {
        MybatisPlusAutoConfig.logger.debug("Could not determine auto-configuration package, automatic mapper scanning disabled." + var7);
    }

}
 
/**
 * http message converter fastjson实现实例
 * 通过fastjson方式进行格式化返回json字符串
 *
 * @return http message converter
 */
@Bean
@ConditionalOnMissingBean
HttpMessageConverters fastJsonHttpMessageConverters() {
    FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
    //创建fastJson配置实体类
    FastJsonConfig fastJsonConfig = new FastJsonConfig();
    fastJsonConfig.setSerializerFeatures(
            SerializerFeature.DisableCircularReferenceDetect,
            SerializerFeature.WriteMapNullValue,
            SerializerFeature.WriteNullListAsEmpty,
            SerializerFeature.WriteNullStringAsEmpty,
            SerializerFeature.WriteNullNumberAsZero,
            SerializerFeature.WriteDateUseDateFormat,
            SerializerFeature.WriteNullBooleanAsFalse
    );

    // get customer define value filters
    List<String> packages = AutoConfigurationPackages.get(beanFactory);
    // get plugin define value filters
    packages.addAll(Arrays.asList(VALUE_FILTER_PACKAGE));

    fastJsonConfig.setSerializeFilters(getDefineFilters(packages));

    fastConverter.setFastJsonConfig(fastJsonConfig);
    return new HttpMessageConverters(fastConverter);
}
 
@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);
    }
}
 
源代码19 项目: api-boot   文件: ApiBootSwaggerAutoConfiguration.java
/**
 * 配置swagger基本信息
 * - BasePackage
 * 默认使用SpringBoot项目扫描bean根目录
 * 如果存在配置时则使用SwaggerProperties.basePackage作为扫描根目录
 *
 * @return Docket实例
 */
@Bean
public Docket docket() {
    String basePackage = swaggerProperties.getBasePackage();
    if (StringUtils.isEmpty(basePackage)) {
        basePackage = AutoConfigurationPackages.get(beanFactory).get(0);
    }
    return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).securitySchemes(Collections.singletonList(apiKey())).securityContexts(Collections.singletonList(securityContext())).select().apis(RequestHandlerSelectors.basePackage(basePackage)).paths(PathSelectors.any()).build();
}
 
源代码20 项目: brpc-java   文件: RpcExporterRegister.java
private Collection<BeanDefinition> getCandidates(ResourceLoader resourceLoader) {
    ClassPathScanningCandidateComponentProvider scanner =
            new ClassPathScanningCandidateComponentProvider(false, environment);

    scanner.addIncludeFilter(new AnnotationTypeFilter(RpcExporter.class));
    scanner.setResourceLoader(resourceLoader);
    return AutoConfigurationPackages.get(beanFactory).stream()
            .flatMap(basePackage -> scanner.findCandidateComponents(basePackage).stream())
            .collect(Collectors.toSet());
}
 
private Set<Imported> prioritize(Set<Imported> registrars) {
	Set<Imported> result = new LinkedHashSet<>();
	for (Imported imported : registrars) {
		if (imported.getType() != null
				&& imported.getType().getName().startsWith(AutoConfigurationPackages.class.getName())) {
			result.add(imported);
		}
	}
	result.addAll(registrars);
	return result;
}
 
源代码22 项目: mdw   文件: AnnotationsScanner.java
/**
 * Source files under src/main/java are scanned for @Activity annotations.
 */
public void findSpringAnnotatedClasses() {
    List<String> scanPackages = AutoConfigurationPackages.get(beanFactory);
    ClassPathScanningCandidateComponentProvider provider = createScannerComponentProvider();
    for (String scanPackage : scanPackages) {
        for (BeanDefinition beanDef : provider.findCandidateComponents(scanPackage)) {
            beanDef.setScope(BeanDefinition.SCOPE_PROTOTYPE);
            addImplementor(beanDef);
        }
    }
}
 
源代码23 项目: wicket-spring-boot   文件: ClassCandidateScanner.java
private static Collection<String> getMappingBasePackages(BeanFactory beanFactory) {
	try {
		return AutoConfigurationPackages.get(beanFactory);
	}
	catch (IllegalStateException ex) {
		// no auto-configuration package registered yet
		return Collections.emptyList();
	}
}
 
源代码24 项目: Mapper   文件: MapperAutoConfiguration.java
@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);
            }
        }
        BaseProperties properties = SpringBootBindUtil.bind(environment, BaseProperties.class, BaseProperties.MYBATIS_PREFIX);
        if(properties != null && properties.getBasePackages() != null && properties.getBasePackages().length > 0){
            packages.addAll(Arrays.asList(properties.getBasePackages()));
        } else {
            //设置了包名的情况下,不需要指定该注解
            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);
    }
}
 
源代码25 项目: moduliths   文件: ModuleBTest.java
@Test // #4
void tweaksAutoConfigurationPackageToModulePackage() {

	assertThat(AutoConfigurationPackages.get(context)) //
			.containsExactly(getClass().getPackage().getName());
}
 
源代码26 项目: brpc-java   文件: AbstractRegister.java
protected Collection<String> getBasePackages() {
    return AutoConfigurationPackages.get(beanFactory);
}
 
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
	AutoConfigurationPackages.register(registry, EventPublication.class.getPackage().getName());
}
 
protected String[] getBasePackages() {
	return AutoConfigurationPackages.get(this.getBeanFactory())
			.toArray(new String[] {});
}
 
protected String[] getBasePackages() {
	return AutoConfigurationPackages.get(this.getBeanFactory())
			.toArray(new String[] {});
}
 
protected String[] getBasePackages() {
	return AutoConfigurationPackages.get(this.getBeanFactory())
			.toArray(new String[] {});
}
 
源代码评论
动弹
沙发等你来抢
 类方法
 同包方法