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

Post Top Ad

Responsive Ads Here

Post Top Ad

Responsive Ads Here

Wednesday, September 3, 2008

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.


<beans>
<bean id=".." class="...">
...
</bean>
...
<beans>
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.

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

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.

Related Articles

6 comments:

  1. Spring.NET uses object instead bean

    ReplyDelete
  2. Yes, that's true. Spring.net uses "objects" and "object" while the other is using "beans" and "bean". Not sure why.

    ReplyDelete
  3. Seems your argument is correct.

    ReplyDelete
  4. 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 .

    http://en.wikipedia.org/wiki/JavaBean

    ReplyDelete
  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.
    Cheers.

    ReplyDelete
  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.

    ReplyDelete

Post Top Ad

Responsive Ads Here