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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:13:04+00:00 2026-05-24T12:13:04+00:00

I am trying to understand programming logic behind the beans of Spring. In examples

  • 0

I am trying to understand programming logic behind the beans of Spring. In examples it is often given them a concrete name like “Duke” or “Kenny”, moreover concrete values also given for constructors and setters which are injected in xml. I think about beans in more general way, say:

Student basicStudent = new Student(grade, name); // gives me certain amount of flexibility where say for grade and name I can have different values, then I can deploy this new student to database. And every unique web request, lets say, I can recreate various instances of different students with this line. 

But with .xml what do I do? I retrieve static bean with predefined values:

Student Bob= (Student)appContext.getBean("Bob"); // where this bean is set with predefined values

Hopefully my confusion will be understood, I can’t think of application of Spring Beans. I am not production developer , just a student, so I may miss some important concept in here. Why would I need preloaded beans with unique instance of a class?

Thank You,

  • 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-24T12:13:05+00:00Added an answer on May 24, 2026 at 12:13 pm

    Spring is generally a framework to support enterprise development, which almost always means some kind of web application (GUI or API) with some business logic embedded. If you were to write even a trivial Java web application and give it some meaningful structure–meaning your code isn’t all packed into one, massive class with no division of responsibility–you’ll quickly begin to run into questions like, “Who/what should be responsible for creating instances of these classes?” and, “How do the instances get ahold of other instances (dependencies) that they need?” These questions lead naturally into the need for a Dependency Injection/Inversion of Control container, which Spring is.

    Further, if you’re practicing test-driven development, which there’s no excuse for any new developer not to be practicing, you’ll find further tension in the “getting dependencies” question, as an object that creates its own dependencies internally is very difficult to test as compared to an object that allows its dependencies to be injected.

    This can only be the barest beginning of an answer, but let me know if it helps and if there’s something else that I can clarify.

    Update: Regarding your question of creating beans to represent each Student: That’s not quite the way that Spring–or Dependency Injection containers in general–are intended to be used. You wouldn’t write an XML bean definition for every single Student in your app. There’s a sometimes-fuzzy line between different “kinds” of objects.

    There are objects that hold distinct state that differentiate them from other objects of the same type. We tend to call this type of object an “entity” or “domain object”. Your Student and Teacher are perfect examples. Each instance of those objects would represent a specific person.

    The other kind of object is the kind that has no distinct state that differentiates it from other objects of the same type. More importantly, it has no state with respect to any specific entity instance. An example of this might be a Data Access Object (DAO), which encapsulates and hides the complexity of interacting with a relational database. It has state, like a connection pool that it draws database connections from in order to do its work, but whether you have one instance of the DAO or 100, they’re all identical and interchangeable.

    We always use Spring to manage the latter category of objects–the ones that are stateless with respect to the other objects that they interact with. Typically, we just create one of each (scope=”singleton”, which is the Spring default), and let Spring wire them all together so that all dependencies are filled.

    For the other category–the entities–some people use Spring to inject dependencies into them, and some don’t. Nobody explicitly creates each of their entity objects as a Spring bean in an XML file, though. Entities are always created using the new operator, whether by you or by some other framework that’s handling them for you. There are other ways of letting Spring manage an object, though. For example, using AspectJ, you can weave bytecode in such a way that when you invoke a constructor (like with new Student()), not only is the instance created, but Spring performs dependency injection on it as well. This is more the style of DI that you would use with an entity.

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

Sidebar

Related Questions

I rather like the prototype way of programming and have been trying to understand
I am trying to understand the programming of Siemens scanner using C++ and given
I have a legacy code to maintain and while trying to understand the logic
I'm trying to understand how this functional reactive programming works, and I have run
I'm trying to understand the differences between some of the newer web programming frameworks
For last 48 hours, I have been trying to understand Multithreading and Socket Programming
I am trying to understand the basics of C programming and I'm kind of
I'm trying to understand what a JavaScript array is because traditional programming languages define
Possible Duplicate: Socket Programming for Windows C/C++ I am trying to understand what my
I'm kinda new to concurrent programming, and trying to understand the benefits of using

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.