本文整理了Java中io.micronaut.context.env.Environment.scan()
方法的一些代码示例,展示了Environment.scan()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Environment.scan()
方法的具体详情如下:
包路径:io.micronaut.context.env.Environment
类名称:Environment
方法名:scan
[英]Scan the current environment for classes annotated with the given annotation. Use with care, repeated invocations should be avoided for performance reasons.
[中]扫描当前环境中使用给定注释注释的类。小心使用,出于性能原因,应避免重复调用。
代码示例来源:origin: io.micronaut/micronaut-inject
private boolean matchesPresenceOfEntities(ConditionContext context, AnnotationValue<Requires> annotationValue) {
if (annotationValue.contains("entities")) {
Optional<AnnotationClassValue[]> classNames = annotationValue.get("entities", AnnotationClassValue[].class);
if (classNames.isPresent()) {
BeanContext beanContext = context.getBeanContext();
if (beanContext instanceof ApplicationContext) {
ApplicationContext applicationContext = (ApplicationContext) beanContext;
final AnnotationClassValue[] classValues = classNames.get();
for (AnnotationClassValue<?> classValue : classValues) {
final Optional<? extends Class<?>> entityType = classValue.getType();
if (!entityType.isPresent()) {
context.fail("Annotation type [" + classValue.getName() + "] not present on classpath");
return false;
} else {
Environment environment = applicationContext.getEnvironment();
Class annotationType = entityType.get();
if (!environment.scan(annotationType).findFirst().isPresent()) {
context.fail("No entities found in packages [" + String.join(", ", environment.getPackages()) + "] for annotation: " + annotationType);
return false;
}
}
}
}
}
}
return true;
}
代码示例来源:origin: io.micronaut/inject
private boolean matchesPresenceOfEntities(ConditionContext context, AnnotationValue<Requires> annotationValue) {
if (annotationValue.contains("entities")) {
Optional<AnnotationClassValue[]> classNames = annotationValue.get("entities", AnnotationClassValue[].class);
if (classNames.isPresent()) {
BeanContext beanContext = context.getBeanContext();
if (beanContext instanceof ApplicationContext) {
ApplicationContext applicationContext = (ApplicationContext) beanContext;
final AnnotationClassValue[] classValues = classNames.get();
for (AnnotationClassValue<?> classValue : classValues) {
final Optional<? extends Class<?>> entityType = classValue.getType();
if (!entityType.isPresent()) {
context.fail("Annotation type [" + classValue.getName() + "] not present on classpath");
return false;
} else {
Environment environment = applicationContext.getEnvironment();
Class annotationType = entityType.get();
if (!environment.scan(annotationType).findFirst().isPresent()) {
context.fail("No entities found in packages [" + String.join(", ", environment.getPackages()) + "] for annotation: " + annotationType);
return false;
}
}
}
}
}
}
return true;
}
内容来源于网络,如有侵权,请联系作者删除!