Java Code Examples for org.springframework.boot.autoconfigure.AutoConfigurationPackages#get()

The following examples show how to use org.springframework.boot.autoconfigure.AutoConfigurationPackages#get() . 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: MapperAutoConfiguration.java    From mapper-boot-starter with MIT License 6 votes vote down vote up
@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);
    }
}
 
Example 2
Source File: AbstractFunctionExecutionAutoConfigurationExtension.java    From spring-boot-data-geode with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: MapperScannerRegistryConfigurer.java    From AsyncDao with MIT License 6 votes vote down vote up
@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);
    }
}
 
Example 4
Source File: MapperScannerConfigurer.java    From AsyncDao with MIT License 6 votes vote down vote up
@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);
    }
}
 
Example 5
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 6
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 7
Source File: LocMybatisAutoConfiguration.java    From loc-framework with MIT License 6 votes vote down vote up
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);
  }
}
 
Example 8
Source File: MyBatisPlusAutoConfiguration.java    From mybatis-plus-sharding-jdbc-spring-boot-starter with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example 9
Source File: MapperAutoConfiguration.java    From mapper-boot-starter with MIT License 6 votes vote down vote up
@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);
    }
}
 
Example 10
Source File: MapperAutoConfiguration.java    From Mapper with MIT License 5 votes vote down vote up
@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);
    }
}
 
Example 11
Source File: ApiBootMyBatisEnhanceAutoConfiguration.java    From beihu-boot with Apache License 2.0 5 votes vote down vote up
@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
Source File: ClassCandidateScanner.java    From wicket-spring-boot with Apache License 2.0 5 votes vote down vote up
private static Collection<String> getMappingBasePackages(BeanFactory beanFactory) {
	try {
		return AutoConfigurationPackages.get(beanFactory);
	}
	catch (IllegalStateException ex) {
		// no auto-configuration package registered yet
		return Collections.emptyList();
	}
}
 
Example 13
Source File: AnnotationsScanner.java    From mdw with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 14
Source File: ApiBootMyBatisEnhanceAutoConfiguration.java    From api-boot with Apache License 2.0 5 votes vote down vote up
@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 15
Source File: HttpMessageConverterAutoConfiguration.java    From api-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 16
Source File: MybatisPlusAutoConfig.java    From seata-samples with Apache License 2.0 5 votes vote down vote up
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);
    }

}
 
Example 17
Source File: MybatisPlusAutoConfig.java    From seata-samples with Apache License 2.0 5 votes vote down vote up
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);
    }

}
 
Example 18
Source File: OpenAPIBuilder.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 19
Source File: AbstractRegister.java    From brpc-java with Apache License 2.0 4 votes vote down vote up
protected Collection<String> getBasePackages() {
    return AutoConfigurationPackages.get(beanFactory);
}