我所拥有的:
Bean
实现Bean.getStereotypes
中,我返回了由这些接口定义的一组构造型注释。拦截器绑定:
@Documented
@InterceptorBinding
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Translated {
}
构造型:
@Stereotype
@Documented
@Translated
@IndexAnnotated
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface TranslationService {
}
我如何注册刻板印象:
public class CustomBean implements Bean {
@Override
public Set<Class<? extends Annotation>> getStereotypes() {
final Set<Class<? extends Annotation>> definedStereoTypes = Arrays.stream(beanInterface.getAnnotations())
.map((annot) -> annot.annotationType())
.filter((annotType) -> annotType.isAnnotationPresent(Stereotype.class))
.collect(toSet());
final Set<Class<? extends Annotation>> stereotypes = ImmutableSet.<Class<? extends Annotation>>builder()
.addAll(definedStereoTypes)
.add(GlobalStereotype.class)
.build();
log.info("Stereotypes for beans <{}>: {}", id, stereotypes);
return stereotypes;
}
示例用法:
@TranslationService
@ConfigProject("TTS")
public interface FooterTranslationService {
@Nonnull
@Default("The Company")
String getTheCompanySectionTitle();
}
和拦截器实现:
@Slf4j
@Dependent
@Translated
@Interceptor
@Priority(Interceptor.Priority.APPLICATION)
public class TranslationInterceptor {
@AroundInvoke
public Object intercept(@Nonnull final InvocationContext ic) throws Exception {
log.info("Intercepting translation);
return ic.proceed();
}
}
我的假设是,通过在Stereotype
实现中返回Bean
的集合,关联的Translated
拦截器将为此bean注册。
这不会发生。有什么我想念的吗?