views:

140

answers:

2

It's been out for a while so I am wondering if people are using the p XML namespace within their Spring configuration files. Is it a helpful shortcut? Is it a good idea that ended up in the trash can?

Where does the Java community largely stand?

+1  A: 

I've never used it, although remember reading about it when released, and rediscovered it's existence recently when browsing the spring reference docs, but even after that, I still find I write properites out in full.

It sounds like a good idea, but I can never remember the schema URL (since I usually copy and paste these from other spring contexts that don't use the p: namespace)

I'm using IDEA, so maybe that has some clever import/add namespace feature?

mdma
+3  A: 

I use it in every single Spring project I've ever touched. I'd guess my current team has a codebase with at least 50 different Spring files and every one uses the p namespace. It's a lot less typing, and arguably more readable. For instance:

<bean id="fry" class="com.fox">
  <property name="leela" value="fracas" />
  <property name="hawking" ref="panucci" />
  <property name="bender">
    <ref local="uhura" />
  </property>
</bean>

Can much more easily be written as

<bean id="fry" class="com.fox"
  p:leela="fracas
  p:hawking-ref="panucci"
  p:bender="uhura" />

The only drawback is that you lose the ability to use the local semantic, though honestly I don't use it that often.

The Eclipse's Spring IDE supports the p-namespace and will autocomplete property names for beans. You can even modifier-click the property names to jump to their declarations and I believe the refactoring tools support changing property names too (even if they're in p-namespace notation).

Teammates may take a while to get used to it, but after they learn it they'll be thanking you for making the files that much more concise.

jasonmp85
Didn't know about the modifier click...thats cool. Thanks.
HDave