Skip to main content

What is the use of Beans.xml configuration file in Spring Framework application ?

Question about  SpringBeans.xml :-

  1. Is this file the file that configure my Bean Factory? I think that, as well as I pass a text value as the value of a variable I could also inject a bean as a dependency of another bean.

    Is it right?

  2. In this example, can I don't use the SpringBeans.xml file and using in place of the annotation system?



Answer :-

1) This Beans.xml (actually you can name it whatever you want) is a Spring configuration file. It holds a Configuration Metadata.

    

5.2.1 Configuration metadata

As the preceding diagram shows, the Spring Ioc container consumes a form of configuration metadata; this configuration metadata represents how you as an application developer tell the Spring container to instantiate, configure, and assemble the objects in your application........


Read All the information about Configuration Metadata on official site.



Configuration metadata is traditionally supplied in a simple and intuitive XML format, but it is not the only allowed form of configuration metadata (see the answer to your second question)

And yes, you are right: you can inject another bean as a reference.



Q.  What Is Bean in Spring Framework ?


Answer :-


Beans are objects that form the backbone of the application.

A bean is simply an object that is instantiatedassembled and otherwise managed by a Spring IoC container; other than that, there is nothing special about a bean.It is in all other respects one of probably many objects in your application.

Spring beans are defined in a spring configuration file or by using annotations, instantiated by the Spring container, and then injected into your application.

Spring beans will not be singleton design pattern until you explicitly make them to be.The singleton design pattern and the spring scope 'singleton' are different things.You can define different bean scopes depending on your requirements.

The scopes could be :

  1. singleton – Return a single bean instance per Spring IoC container
  2. prototype – Return a new bean instance each time when requested
  3. request – Return a single bean instance per HTTP request.
  4. session – Return a single bean instance per HTTP session.
  5. globalSession – Return a single bean instance per global HTTP session.

The default scope is singleton.














Comments