Java News Tips Software
Java News Tips Software | Contact | Facebook | Twitter RSS

Use "object" instead of "bean" in Spring Configuration XML

Spring configuration xml is used for defining the wiring between different object. It has the following format.

<bean id=".." class="...">

Classes specified in the configuration file will be instantiated by Spring container. And those objects will be bound with each other accordingly. Any java class specified under attribute named "class" will be instantiated. There is no much limitations on the classes that can be used for this here. It does not need to be a JavaBean. It can be any POJO (plan old java object). The only requirement is that this class must be possible to instantiate.

Spring LogoSo why does this tags are named <beans> and <bean>? This seems to be misleading.

In Spring one way of binding objects is using the beaness of java classes. But that is not that only way to bind them together, constructor can be used to bind objects. So if configuration file used tags as follows, it would be more meaningful.

<object id=".." class="...">

Seems it is used only to express that beaness can also be used in initialization. Would you agree? May be we are not seeing the exact reason. This is completely open for discussion.

Labels: , , ,


  1. Spring.NET uses object instead bean
  2. Yes, that's true. uses "objects" and "object" while the other is using "beans" and "bean". Not sure why.
  3. Seems your argument is correct.
  4. Anonymous Myron Davis (Ja) on October 14, 2011 12:22 PM  
    I'm a little new to this but though your arguments do make some sense, I think the use of the and tags grew from the JavaBean convention in Java programming. This is possibly part of the reason why was used in Spring.NET as supposed to .
  5. Hi Myron, Yes I agree, JavaBeans spec must have an impact since Spring uses setters for injection. However the point is there's no requirement for our Java classes to be JavaBean spec complaint to be used inside a Spring config; even factory methods can be invoked using Spring config.
  6. Yes, I agree. I do believe the concept of Spring Beans grew from the JavaBeans concept. I think it was also a way to counter Enterprise Java Beans. If you all remember when Rod Johnson first introduced Spring it was suppose to be the anti-EJB. I think using the term bean was an attempt to reminded developers what EJB should have been (simple and straight forward) versus what it turned out to be (tedious and in many cases overkill). With that said I do think object is a better term than bean, but after 9 years of beans it may be tough (initially at least) to get developers to see it any other way.
Page Views :
Email :
Select Month:
Free counter and web stats