programmatic interceptor bindings in @BuildStep

17 views
Skip to first unread message

William Burke

unread,
Mar 17, 2026, 4:42:59 PM (6 days ago) Mar 17
to Quarkus Development mailing list
I want to add an interceptor to a bean class without defining a @InterceptorBinding.  Is this possible?  I'm searching right now and can't seem to find an example.

--
Bill Burke
IBM

William Burke

unread,
Mar 17, 2026, 4:59:00 PM (6 days ago) Mar 17
to Quarkus Development mailing list
Alternatively, a way to associate an interceptor an InterceptorBinding

I'm defining a custom scope annotation @InvocationScoped that I want to also trigger adding an interceptor to the bean class, but I want this interceptor to be a @Singleton.

@Interceptor
@Singleton
@InvocationScoped
@Priority(Interceptor.Priority.PLATFORM_BEFORE + 100)
public class InvocationScopeInterceptor {



@NormalScope
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@InterceptorBinding
public @interface InvocationScoped {

}

 
--
Bill Burke
IBM

Ladislav Thon

unread,
Mar 17, 2026, 5:55:17 PM (6 days ago) Mar 17
to quark...@googlegroups.com
út 17. 3. 2026 v 21:42 odesílatel 'William Burke' via Quarkus Development mailing list <quark...@googlegroups.com> napsal:
I want to add an interceptor to a bean class without defining a @InterceptorBinding.  Is this possible?  I'm searching right now and can't seem to find an example.

You can do all kinds of things like this using an annotation transformation. Look for `AnnotationsTransformerBuildItem` -- there are [at least] two, you want the ArC's one. The transformation basically goes like: if the target declaration is a class that has a given scope annotation, add an interceptor binding annotation.

LT
 

--
Bill Burke
IBM

--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/quarkus-dev/CAL%3DE%3DjSf5um%2BamvpzxFJGBXV5S4fcgPpOD0JV3M-00D7xjKKqw%40mail.gmail.com.

Martin Kouba

unread,
Mar 18, 2026, 3:05:15 AM (5 days ago) Mar 18
to 'William Burke' via Quarkus Development mailing list
On 3/17/26 21:58, 'William Burke' via Quarkus Development mailing list
wrote:
> Alternatively, a way to associate an interceptor an InterceptorBinding
>
> I'm defining a custom scope annotation @InvocationScoped that I want to
> also trigger adding an interceptor to the bean class, but I want this
> interceptor to be a @Singleton.

An interceptor is always @Dependent, i.e. "The lifecycle of an
interceptor instance is the same as that of the target instance with
which it is associated.". In other words, you can't make it @Singleton.

>
> @Interceptor
> @Singleton
> @InvocationScoped
> @Priority(Interceptor.Priority.PLATFORM_BEFORE+ 100)
> publicclassInvocationScopeInterceptor{
>
>
>
> @NormalScope
> @Inherited
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE})
> @InterceptorBinding
> public@interfaceInvocationScoped{
>
> }
>
>
> On Tue, Mar 17, 2026 at 4:42 PM William Burke <bbu...@redhat.com
> <mailto:bbu...@redhat.com>> wrote:
>
> I want to add an interceptor to a bean class without defining
> a @InterceptorBinding.  Is this possible?  I'm searching right now
> and can't seem to find an example.
>
> --
> Bill Burke
> IBM
>
>
>
> --
> Bill Burke
> IBM
>
> --
> You received this message because you are subscribed to the Google
> Groups "Quarkus Development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to quarkus-dev...@googlegroups.com <mailto:quarkus-
> dev+uns...@googlegroups.com>.
> To view this discussion visit https://groups.google.com/d/msgid/quarkus-
> dev/
> CAL%3DE%3DjTd7DcqnSCYnopfx7yBB4PfQ0Naa5F0h1DVq6Rte4GktA%40mail.gmail.com
> <https://groups.google.com/d/msgid/quarkus-dev/
> CAL%3DE%3DjTd7DcqnSCYnopfx7yBB4PfQ0Naa5F0h1DVq6Rte4GktA%40mail.gmail.com?utm_medium=email&utm_source=footer>.

William Burke

unread,
Mar 18, 2026, 9:03:55 AM (5 days ago) Mar 18
to quark...@googlegroups.com
On Wed, Mar 18, 2026 at 3:05 AM 'Martin Kouba' via Quarkus Development mailing list <quark...@googlegroups.com> wrote:
On 3/17/26 21:58, 'William Burke' via Quarkus Development mailing list
wrote:
> Alternatively, a way to associate an interceptor an InterceptorBinding
>
> I'm defining a custom scope annotation @InvocationScoped that I want to
> also trigger adding an interceptor to the bean class, but I want this
> interceptor to be a @Singleton.

An interceptor is always @Dependent, i.e. "The lifecycle of an
interceptor instance is the same as that of the target instance with
which it is associated.". In other words, you can't make it @Singleton.


Gemini lies!!  Told me it was @Dependent by default.

How does @ActivateRequestContext work then if it is dependent? Or can you only use that annotation on larger scoped beans like session and applicationscoped?

public class My Bean {
}


--
Bill Burke
IBM

Martin Kouba

unread,
Mar 19, 2026, 6:14:48 AM (4 days ago) Mar 19
to 'William Burke' via Quarkus Development mailing list
On 3/18/26 14:03, 'William Burke' via Quarkus Development mailing list
wrote:
>
>
> On Wed, Mar 18, 2026 at 3:05 AM 'Martin Kouba' via Quarkus Development
> mailing list <quark...@googlegroups.com <mailto:quarkus-
> d...@googlegroups.com>> wrote:
>
> On 3/17/26 21:58, 'William Burke' via Quarkus Development mailing list
> wrote:
> > Alternatively, a way to associate an interceptor an
> InterceptorBinding
> >
> > I'm defining a custom scope annotation @InvocationScoped that I
> want to
> > also trigger adding an interceptor to the bean class, but I want
> this
> > interceptor to be a @Singleton.
>
> An interceptor is always @Dependent, i.e. "The lifecycle of an
> interceptor instance is the same as that of the target instance with
> which it is associated.". In other words, you can't make it @Singleton.
>
>
> Gemini lies!!  Told me it was @Dependent by default.

Oh yes, these things sometimes lie you know ;-)

I tried Claude Heiku 4.5 and it got it almost right, except that it
claimed that it's a hard requirement in the spec.

In fact, the spec states:
"If an interceptor has any scope other than @Dependent, non-portable
behavior results." And non-portable behavior is bad, m'kay. And it won't
work in ArC.

>
> How does @ActivateRequestContext work then if it is dependent? Or can
> you only use that annotation on larger scoped beans like session and
> applicationscoped?

ActivateRequestContext is just a regular interceptor binding. If you
annotate a bean class, then the interceptor is used for all business
methods.

>
> @RequestScoped
> @ActivateRequestContext
> public class MyBean {
> }

Good question. I think that this should not work, because the
interceptor is associated with the MyBean contextual instance, and so
you need to lookup the contextual instance first.

In other words, you can do that but the ActivateRequestContext
interceptor will not help if the request context is not active when a
MyBean method is invoked.

>
>
> --
> Bill Burke
> IBM
>
> --
> You received this message because you are subscribed to the Google
> Groups "Quarkus Development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to quarkus-dev...@googlegroups.com <mailto:quarkus-
> dev+uns...@googlegroups.com>.
> To view this discussion visit https://groups.google.com/d/msgid/quarkus-
> dev/
> CAL%3DE%3DjRQLz4CYZ1GzPOLDREWNtQ4RCgM8QFQO6uDs3L2V95qrw%40mail.gmail.com
> <https://groups.google.com/d/msgid/quarkus-dev/
> CAL%3DE%3DjRQLz4CYZ1GzPOLDREWNtQ4RCgM8QFQO6uDs3L2V95qrw%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Reply all
Reply to author
Forward
0 new messages