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

  • Home
  • SEARCH
  • 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 7017005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:51:32+00:00 2026-05-27T22:51:32+00:00

Is it possible to inject a request-scoped CDI bean into a Stateless session bean?

  • 0

Is it possible to inject a request-scoped CDI bean into a Stateless session bean?

I had asked a related question and thought the specific CDI @RequestScoped into @Stateless question merited its own post.

Passing state between EJB methods / @RequestScoped and @Stateless

I also asked a similar question about JMS @MessageDriven beans – basically want to know the same about @Stateless.

@RequestScoped CDI injection into @MessageDriven bean

  • 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-27T22:51:32+00:00Added an answer on May 27, 2026 at 10:51 pm

    You can absolutely do what you mention and use @RequestScoped beans in an @Stateless session bean and an @MessageDriven bean. This is a core part of the CDI spec and TCK and guaranteed portable.

    Note on MDBs

    Do be aware that there is a test for a @Stateless bean that uses a @RequestScoped bean, but there is no test that guarantees a @MessageDriven bean can reference @RequestScoped beans. This was just an oversight and is already fixed for the Java EE 7 TCK. So just be aware that if it doesn’t work for the MDB case, it may not be your fault 🙂

    The workaround would be to simply have your MDB delegate to a SessionBean of any kind as @Stateless, @Stateful, and @Singleton all have @RequestScoped tests.

    Making the EJB, itself, scoped

    While @Stateless, @Singleton and @MessageDriven can have scoped references injected via @Inject, they cannot be @RequestScoped or any other scope. Only the @Stateful model is flexible enough to support scopes. In other words, you can annotate the @Stateful bean class itself as @RequestScoped, @SessionScoped, etc..

    In simple terms @Stateless, @Singleton have fixed "scopes" already. @Singleton is essentially @ApplicationScoped and @Stateless would perhaps be some made-up scope like @InvocationScoped, if that existed. The lifecycle of an @MessageDriven bean is entirely up to the Connector that drives it and is therefore also not allowed to have user-defined scope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it at all possible to inject a request into IIS for a page,
It is possible to inject entity manager (or its factory) into jsf managed bean
Is it possible to inject EJB 3.1 beans into POJO using CDI on Glassfish
Is is possible to inject IPrincipal using Castle Windsor into my asp.net mvc controller.
Is it possible to inject an interface into an existing 3rd party class that
Is it possible to inject ejb's into pojo's using the @EJB annotation? If it
I was wondering if its possible to inject a thread into a remote app
Is it possible to have Spring inject the JPA entityManager object into my DAO
Is it possible to inject Spring beans into an RestEasy @Path class? I managed
With the new EJB 3.1 spec is it possible to inject an EJB into

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.