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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:28:55+00:00 2026-05-31T14:28:55+00:00

I am trying to understand how Dependency Injection works. I am reading Pro Spring

  • 0

I am trying to understand how Dependency Injection works. I am reading Pro Spring 2.5 and have gotten to chapter 3. Some questions that has come to my mind is:

When you make the bean factory in the main method of your stand alone application (it would be interesting to know in a web app too) and then read the bean configuration file, what happens then?
Does it create the beans with their dependencies at that point and keeps those in a register or is it just the configuration information it keeps in the register?

I understand that you should try to keep dependency lookup to a minimum so if you have a MyApplication class or something that bootstraps the application that is preferred. Now, how would Spring or the POJO’s know where and when to inject the dependencies if the factory with the register is only available in the main method? Isn’t the register only available in the main method? Since you are not calling “getBean(…)” anymore where does the constructing take place? How does it manage to keep the beans as singletons etc?

  • 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-31T14:28:57+00:00Added an answer on May 31, 2026 at 2:28 pm

    Does it create the beans with their dependencies at that point and keeps those in a register

    Yes, by default once you create an instance of BeanFactory or ApplicationContext (see: BeanFactory vs ApplicationContext) Spring creates all beans and wires them up. The exception are beans with lazy scope, but if they are dependants of non-lazy beans, they will be created despite that.

    Spring also manages correct order of bean initialization.

    Now, how would Spring or the POJO’s know where and when to inject the dependencies

    Basically, all the beans live inside the Spring container. If you fetch one bean, it already has references to its direct dependencies. They in turns have dependencies to other. The bottom line is: all beans are typically created and wired up at startup and they are sort-of singletons.

    See also

    • Using Spring in standalone apps
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to see if I understand depedency injection. I have a project that
I'm trying to understand the best way to use Spring (for dependency injection) with
I have recently started reading about dependency injection and it has made me rethink
Just trying to understand that - I have never used it before. How is
I have been trying to understand and get something working with dependency properties. I
Currently I'm trying to understand dependency injection better and I'm using asp.net MVC to
I have been reading on Dependency properties for a few days and understand how
I've been trying to understand how Ruby blocks work, and to do that I've
I have been trying to understand a bit more about the wider picture of
I am a newbie in Spring and am trying to understand the below concept.

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.