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 7918543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:32:50+00:00 2026-06-03T15:32:50+00:00

In CDI you can define an object that will give you items of a

  • 0

In CDI you can define an object that will give you items of a certain type, using:

@Inject
Instance<MyObject> myObjectInstance;
//...
MyObject myObjectInstance.get();

Similarly in Guice you can do:

@Inject
Provider<MyObject> myObjectInstance;
//...
MyObject myObjectInstance.get();

I am wondering if there is a similar construct in Spring, or you must use the ApplicationContext in order to get the reference?

  • 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-06-03T15:32:51+00:00Added an answer on June 3, 2026 at 3:32 pm

    So after a lot of digging around I found out that Spring supports JSR-330. This JSR defines a simple API – the whole spec is literally just this API – that standardizes several dependency injection interfaces, annotations and behaviors.

    Unlike Spring’s FactoryBean the javax.inject.Provider interface doesn’t throws Exception on getting the bean reference. Furthermore, you would still need to define this FactoryBean in some place (read XML, or @Configuration class, and this is suboptimal).

    Due to a bug, in current Spring 3.1.1, the javax.inject.Provider does not work. It does work in Spring 3.1.0.

    In order to use it you simple need to include the javax.inject jar – if you use maven you can:

        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>
    

    Spring will detect it, and from that moment on you can simply:

    @Inject
    Provider<MyObject> myObjectInstance;
    //...
    MyObject myObjectInstance.get();
    

    like in the Guice example, since it is the same API.

    Despite my previous comment to Konstantin, Spring does create the Provider by itself. (I was testing it against Spring 3.1.1 and run into this Spring Provider regression issue)

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

Sidebar

Related Questions

How can I use JSR-299 CDI to inject (not annotated) beans from external libraries?
I'm playing with CDI producers and spotted in doc that InjectionPoint.getBean() can return null
I wrote a converter. I am using CDI and injection parallel. In that case
With the concept of CDI in EJB3.X, you can inject the beans or entities.
Here's a recurrent problem that I have and I think maybe CDI events can
When using CDI and JSF2 How can a HTTP request parameter be injected into
how can I Inject a Bean, that uses a @Named annotation along with a
Is there an existing, or upcoming book on CDI/Weld that you can recommend? I'm
I'm using CDI (Weld) and I've faced a problem, hope you can help. I
I've written a JEE6 application using CDI and JPA. My tests are written in

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.