Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7072571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:49:30+00:00 2026-05-28T05:49:30+00:00

I have some beans for which, in specific injections, I want to add a

  • 0

I have some beans for which, in specific injections, I want to add a given interceptor.

I was naïvely thinking there was something like a @Interceptors annotation that could allow me to write

private @Interceptors(Logging.class, Connection.class) @Inject MyBean instance;

Unfortunatly, Weld documentation clearly states the opposite.

So, how could I inject an intercepted version of my bean ? Is it possible using a cdi Instance object ?

EDIT

Although LightGuard’s answser is really relevant, it doesn’t totally answser my question, so let me rephrase it.

I want to have an annotation that triggers some kind of method call event sending. For that, I created a CDI Interceptor, complete with its own interceptor binding (let’s say interceptor is called SenderInterceptor, and the binding is called SenderBinding). What I want now is to add a CDI qualifier (let’s call it SenderQualifier) that, when used for an injection, installs SenderInterceptor.

To be more clear, I want the following code to use SenderInterceptor

/* calling any method of that bean should trigger an event */
private @Inject @SenderQualifier MyBean aBean;

while this one doesn’t

private @Inject MyBean aBean;

What I tried so far was

  • detecting fields requiring those injections using reflections library (that works)
  • create using seam solder an AnnotatedType from bean class (during the BeforeBeanDiscovery event) (the type is created, but not really distinguishable from the initial one) and giving that AnnotatedType the interceptor binding annotation.
  • create using seam solder (again) a Bean from generated AnnotatedType, and giving it the required qualifier annotation

All seems to worrk, except it’s the original bean which gets injected.

I could of course replace original one with intercepted one, but there are some cases where such interception is not required, so I have to keep both AnnotatedType refering the same concrete type. I was thinking I coulld do that in CDI, but it doesn’t seems to work (as original type is never replaced by intercepted one).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:49:30+00:00Added an answer on May 28, 2026 at 5:49 am

    What you would need to do:

    1. Add the interceptor to beans.xml so it’s activated
    2. Create an extension to add the interceptor binding or the interceptor annotation to the type in ProcessAnnotatedType life cycle event. You’ll need to call getAnnotatedType, add the annotation(s) then call setAnnotatedType. I strongly recommend looking at Seam Solder or Apache DeltaSpike project for the AnnotatedTypeBuilder to make this easier.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of Spring beans some of which need to be initialized
I have some beans which I create which all use a similar pattern for
I have a method invoking bean which calls a method to perform some sort
I've got some 3rd party beans that have method signatures that fit quite well
I have some arbitrary pixel data that I want to save as a PNG.
I have some text lines like that : vt_wildshade2^508^508 vt_ailleurs2^1188^1188 ... vt_high2^13652^13652 Is it
I have some tables roughly like so: Client: id name Employee id name Email
I have some code that will change the background color of a specific label
I have come across some java classes used in the spring framework. First, there
I have a bunch of projects which declare some spring bean files. I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.