I am new to ByteBuddy and have simple question. Is there any way how to composite interceptors together fe via annotation. Something like:
@Logging
@Transactional
public void foo() {}
Would add logging interceptor and also make sure it's transactional?
Of course, if you use a ByteBuddy
instanace, it is up to the used ElementMatcher
used:
annotatedWith(Logging.class).or(annotatedWith(Transactional.class))
When you are using an AgentBuilder
, you would define one instrumentation for each type where you can combine different type matchers using
.type(declaresMethod(annotatedWith(Logging.class)))
.transform(new LoggingTranformer())
.asDecorator()
.type(declaresMethod(annotatedWith(Transactional.class)))
.transform(new TransactionalTranformer())
.asDecorator()
Using the asDecorator()
command, the two transformers are chained.
Thanks to Rafael Winterhalter and discussion I am posting his suggested answer:
You would need to write your own generic dispatcher. I would suggest you to create some form of generic dispatcher which then delegate programmatically.
For example:isAnnotatedWith(anyOf(dispatcher.getAnnotationTypes())
where the dispatcher then routes to the components in question.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.