本文整理汇总了Java中org.springframework.core.type.classreading.MetadataReader类的典型用法代码示例。如果您正苦于以下问题:Java MetadataReader类的具体用法?Java MetadataReader怎么用?Java MetadataReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MetadataReader类属于org.springframework.core.type.classreading包,在下文中一共展示了MetadataReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDelegatingTypeExcludeFilter
import org.springframework.core.type.classreading.MetadataReader; //导入依赖的package包/类
private TypeExcludeFilter createDelegatingTypeExcludeFilter() {
final Set<TypeExcludeFilter> filters = new LinkedHashSet<TypeExcludeFilter>(
this.filterClasses.size());
for (Class<? extends TypeExcludeFilter> filterClass : this.filterClasses) {
filters.add(createTypeExcludeFilter(filterClass));
}
return new TypeExcludeFilter() {
@Override
public boolean match(MetadataReader metadataReader,
MetadataReaderFactory metadataReaderFactory) throws IOException {
for (TypeExcludeFilter filter : filters) {
if (filter.match(metadataReader, metadataReaderFactory)) {
return true;
}
}
return false;
}
};
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:22,代码来源:TypeExcludeFiltersContextCustomizer.java
示例2: scanPackages
import org.springframework.core.type.classreading.MetadataReader; //导入依赖的package包/类
/**
* <p>根据多个包名搜索class
* 例如: ScanClassUtils.scanPakcages("javacommon.**.*");</p>
*
* @param basePackages 各个包名使用逗号分隔,各个包名可以有通配符
* @return 类名的集合
*/
@SuppressWarnings("all")
public static List<String> scanPackages(String basePackages) {
Assert.notNull(basePackages,"'basePakcages' must be not null");
ResourcePatternResolver rl = new PathMatchingResourcePatternResolver();
MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(rl);
List<String> result = new ArrayList<String>();
String[] arrayPackages = basePackages.split(",");
try {
for(int j = 0; j < arrayPackages.length; j++) {
String packageToScan = arrayPackages[j];
String packagePart = packageToScan.replace('.', '/');
String classPattern = "classpath*:/" + packagePart + "/**/*.class";
Resource[] resources = rl.getResources(classPattern);
for (int i = 0; i < resources.length; i++) {
Resource resource = resources[i];
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
String className = metadataReader.getClassMetadata().getClassName();
result.add(className);
}
}
} catch(Exception e) {
throw new RuntimeException(String.format("Scanning package[%s] class occurred an error!", basePackages), e);
}
return result;
}
示例3: loadClassName
import org.springframework.core.type.classreading.MetadataReader; //导入依赖的package包/类
/**
* 加载资源,根据resource获取className
*
* @param metadataReaderFactory spring中用来读取resource为class的工具
* @param resource 这里的资源就是一个Class
* @throws IOException
*/
private static String loadClassName(MetadataReaderFactory metadataReaderFactory, Resource resource)
throws IOException
{
try
{
if (resource.isReadable())
{
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
if (metadataReader != null)
{
return metadataReader.getClassMetadata().getClassName();
}
}
}
catch (Exception e)
{
LOG.error("根据resource获取类名称失败", e);
}
return null;
}
示例4: findMyTypes
import org.springframework.core.type.classreading.MetadataReader; //导入依赖的package包/类
protected List<Class<?>> findMyTypes(String basePackage) throws IOException, ClassNotFoundException {
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resourcePatternResolver);
List<Class<?>> candidates = new ArrayList<>();
String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resolveBasePackage(basePackage)
+ "/" + "**/*.class";
Resource[] resources = resourcePatternResolver.getResources(packageSearchPath);
for (Resource resource : resources) {
if (resource.isReadable()) {
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
if (isCandidate(metadataReader)) {
candidates.add(forName(metadataReader.getClassMetadata().getClassName()));
}
}
}
return candidates;
}
示例5: findMangoDaoClasses
import org.springframework.core.type.classreading.MetadataReader; //导入依赖的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);
}
}
示例6: getClassSet
import org.springframework.core.type.classreading.MetadataReader; //导入依赖的package包/类
/**
* 将符合条件的Bean以Class集合的形式返回
*
* @return
* @throws IOException
* @throws ClassNotFoundException
*/
public Set<Class<?>> getClassSet() throws IOException, ClassNotFoundException {
this.classSet.clear();
if (!this.packagesList.isEmpty()) {
for (String pkg : this.packagesList) {
String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
+ ClassUtils.convertClassNameToResourcePath(pkg) + RESOURCE_PATTERN;
Resource[] resources = this.resourcePatternResolver.getResources(pattern);
MetadataReaderFactory readerFactory = new CachingMetadataReaderFactory(this.resourcePatternResolver);
for (Resource resource : resources) {
if (resource.isReadable()) {
MetadataReader reader = readerFactory.getMetadataReader(resource);
String className = reader.getClassMetadata().getClassName();
if (matchesEntityTypeFilter(reader, readerFactory)) {
this.classSet.add(Class.forName(className));
}
}
}
}
}
return this.classSet;
}
示例7: scan
import org.springframework.core.type.classreading.MetadataReader; //导入依赖的package包/类
/**
* 将符合条件的Bean以Class集合的形式返回
* @throws Exception 异常
* @return 类集合
*/
public Set<Class<?>> scan() throws Exception {
Set<Class<?>> classSet = new HashSet<Class<?>>();
if (!this.packagesList.isEmpty()) {
for (String pkg : this.packagesList) {
String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX +
ClassUtils.convertClassNameToResourcePath(pkg) + RESOURCE_PATTERN;
Resource[] resources = this.resourcePatternResolver.getResources(pattern);
MetadataReaderFactory readerFactory = new CachingMetadataReaderFactory(this.resourcePatternResolver);
for (Resource resource : resources) {
if (resource.isReadable()) {
MetadataReader reader = readerFactory.getMetadataReader(resource);
String className = reader.getClassMetadata().getClassName();
if (matchesEntityTypeFilter(reader, readerFactory)) {
classSet.add(Class.forName(className));
}
}
}
}
}
return classSet;
}
示例8: loadClassName
import org.springframework.core.type.classreading.MetadataReader; //导入依赖的package包/类
/**
* 加载资源,根据resource获取className
*
* @param metadataReaderFactory
* spring中用来读取resource为class的工具
* @param resource
* 这里的资源就是一个Class
* @throws IOException
*/
private static String loadClassName(MetadataReaderFactory metadataReaderFactory, Resource resource)
throws IOException {
try {
if (resource.isReadable()) {
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
if (metadataReader != null) {
return metadataReader.getClassMetadata().getClassName();
}
}
}
catch (Exception e) {
log.error("根据resource获取类名称失败", e);
}
return null;
}
示例9: registerFilters
import org.springframework.core.type.classreading.MetadataReader; //导入依赖的package包/类
/**
* Configures parent scanner to search for the right interfaces. It can search
* for all interfaces or just for those that extends a markerInterface or/and
* those annotated with the annotationClass
*/
public void registerFilters() {
if (Envs.classExists("org.n3r.eql.eqler.annotations.Eqler")) {
addExcludeFilter(new AnnotationTypeFilter(Eqler.class));
addExcludeFilter(new AnnotationTypeFilter(EqlerConfig.class));
}
addIncludeFilter(new TypeFilter() {
@Override
public boolean match(MetadataReader metadataReader,
MetadataReaderFactory metadataReaderFactory
) throws IOException {
val metadata = metadataReader.getClassMetadata();
if (!metadata.isInterface()) return false;
val className = metadata.getClassName();
val clazz = Envs.forName(className);
return Anns.isFastWestCacheAnnotated(clazz);
}
});
}
示例10: match
import org.springframework.core.type.classreading.MetadataReader; //导入依赖的package包/类
@Override
public boolean match(MetadataReader metadataReader,
MetadataReaderFactory metadataReaderFactory) throws IOException {
if (isTestConfiguration(metadataReader)) {
return true;
}
if (isTestClass(metadataReader)) {
return true;
}
String enclosing = metadataReader.getClassMetadata().getEnclosingClassName();
if (enclosing != null) {
try {
if (match(metadataReaderFactory.getMetadataReader(enclosing),
metadataReaderFactory)) {
return true;
}
}
catch (Exception ex) {
// Ignore
}
}
return false;
}
示例11: findConfigurationClasses
import org.springframework.core.type.classreading.MetadataReader; //导入依赖的package包/类
private Set<AnnotationMetadata> findConfigurationClasses() throws IOException {
Set<AnnotationMetadata> configurationClasses = new HashSet<AnnotationMetadata>();
Resource[] resources = this.resolver.getResources("classpath*:"
+ getClass().getPackage().getName().replace(".", "/") + "/**/*.class");
for (Resource resource : resources) {
if (!isTestClass(resource)) {
MetadataReader metadataReader = new SimpleMetadataReaderFactory()
.getMetadataReader(resource);
AnnotationMetadata annotationMetadata = metadataReader
.getAnnotationMetadata();
if (annotationMetadata.getAnnotationTypes()
.contains(Configuration.class.getName())) {
configurationClasses.add(annotationMetadata);
}
}
}
return configurationClasses;
}
示例12: getClasses
import org.springframework.core.type.classreading.MetadataReader; //导入依赖的package包/类
protected List<String> getClasses(Resource[] resources) {
List<String> classNames = new ArrayList<>();
for (Resource resource : resources) {
if (resource.isReadable()) {
MetadataReader metadataReader;
try {
metadataReader = metadataReaderFactory.getMetadataReader(resource);
} catch (IOException e) {
throw new RuntimeException("Unable to read metadata resource", e);
}
AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
if (annotationMetadata.isAnnotated(com.haulmont.chile.core.annotations.MetaClass.class.getName())
|| annotationMetadata.isAnnotated(MappedSuperclass.class.getName())
|| annotationMetadata.isAnnotated(Entity.class.getName())) {
ClassMetadata classMetadata = metadataReader.getClassMetadata();
classNames.add(classMetadata.getClassName());
}
}
}
return classNames;
}
示例13: getContextCustomizerShouldAddExcludeFilters
import org.springframework.core.type.classreading.MetadataReader; //导入依赖的package包/类
@Test
public void getContextCustomizerShouldAddExcludeFilters() throws Exception {
ContextCustomizer customizer = this.factory
.createContextCustomizer(WithExcludeFilters.class, null);
customizer.customizeContext(this.context, this.mergedContextConfiguration);
this.context.refresh();
TypeExcludeFilter filter = this.context.getBean(TypeExcludeFilter.class);
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
MetadataReader metadataReader = metadataReaderFactory
.getMetadataReader(NoAnnotation.class.getName());
assertThat(filter.match(metadataReader, metadataReaderFactory)).isFalse();
metadataReader = metadataReaderFactory
.getMetadataReader(SimpleExclude.class.getName());
assertThat(filter.match(metadataReader, metadataReaderFactory)).isTrue();
metadataReader = metadataReaderFactory
.getMetadataReader(TestClassAwareExclude.class.getName());
assertThat(filter.match(metadataReader, metadataReaderFactory)).isTrue();
}
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:19,代码来源:TypeExcludeFiltersContextCustomizerFactoryTests.java
示例14: convertTypeAliasesPackage
import org.springframework.core.type.classreading.MetadataReader; //导入依赖的package包/类
/**
* <p>
* 别名通配符设置
* </p>
* <p>
* <property name="typeAliasesPackage" value="com.baomidou.*.entity"/>
* </p>
*
* @param typeAliasesPackage 类别名包路径
* @return
*/
public static String[] convertTypeAliasesPackage(String typeAliasesPackage) {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
String pkg = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
+ ClassUtils.convertClassNameToResourcePath(typeAliasesPackage) + "/*.class";
/*
* 将加载多个绝对匹配的所有Resource
* 将首先通过ClassLoader.getResource("META-INF")加载非模式路径部分,然后进行遍历模式匹配,排除重复包路径
*/
try {
Set<String> set = new HashSet<>();
Resource[] resources = resolver.getResources(pkg);
if (resources != null && resources.length > 0) {
MetadataReader metadataReader;
for (Resource resource : resources) {
if (resource.isReadable()) {
metadataReader = metadataReaderFactory.getMetadataReader(resource);
set.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage().getName());
}
}
}
if (!set.isEmpty()) {
return set.toArray(new String[]{});
} else {
throw new MybatisPlusException("not find typeAliasesPackage:" + pkg);
}
} catch (Exception e) {
throw new MybatisPlusException("not find typeAliasesPackage:" + pkg, e);
}
}
示例15: isCandidate
import org.springframework.core.type.classreading.MetadataReader; //导入依赖的package包/类
protected boolean isCandidate(MetadataReader metadataReader) throws ClassNotFoundException {
try {
Class<?> c = forName(metadataReader.getClassMetadata().getClassName());
if (c.getAnnotation(Configuration.class) != null) {
return true;
}
} catch (Throwable e) {
LOGGER.debug("error {}", e);
}
return false;
}