Monday, August 22, 2005

Spring/Hibernate Training 1

This week I am at a week-long on-site Spring/Hibernate training class taught by Richard Hightower. Now, I've been doing this stuff for a while, so most of the material is not new to me. But still, I am finding bits of interesting information here and there. So here is my "real time" blog on the stuff that other people might also find useful.

Id vs. name

In spring context files, bean definitions can have either an "id" or a "name" attribute. I think I've read about these before, but I couldn't remember exactly what the differences are. Turns out they server the same purpose, i.e. uniquely identifying the bean being defined. The only difference is "name" can be any string ("foo", "/bar" etc.), while "id" has to be a valid XML ID. This difference is significant when you reference a bean, with either "bean" or "local". With "bean", you can use either id or name (e.g. <ref bean="/foo">), but with "local", you can only refer to XML IDREFs, so they have to be IDs. So <ref local="/foo"> would give you an XML validation error.

0 Comments:

Post a Comment

<< Home