Picture of admin

Simple DSL for Configuring Spring Beans

  • Posted By admin on December 02, 2005

I have this working (in skeleton form). Anybody interested?

bean :id=>:one, :class=>:NamedBean do
  set :name, "first" 
end

bean :id=>:nv, :class=>:NameValueBean do 
  set :name, "nv" 
  set :value, :one, :local
end

bean :id=>"sb-with-string", :class=>:ScoreBean do
  constructor 15
end
Comments
  1. SethDecember 02, 2005 @ 02:29 AM
    Why not: bean :one isa :NamedBean with :name "first" end BTW, do one for Spring Web Flow! :)
  2. Josh LucasDecember 02, 2005 @ 10:17 AM
    I would be very, very interested. The bean configuration has been one of the more difficult selling points for Spring at work. I have a feeling this would help quite a bit.
  3. Dion AlmaerDecember 02, 2005 @ 11:15 AM
    Can you get rid of the backslashes? :) Dion
  4. Rob LallyDecember 02, 2005 @ 11:16 AM
    I've been pondering building something like this for a while ... but never got round to it. It seemed to me that there were two ways it could work. 1. Using JRuby it could actually configure the containter. 2. It could spit out an XML file that would be read in by the regular bean factory. Which way have you gone? Either way : looks very pretty.
  5. Bob LeeDecember 02, 2005 @ 11:36 AM
    I prefer BeanShell for this sort of thing. Why use two languages when one will do? bean() .id("one") .type(NamedBean) .set("name", "first"); Now that I think about it, BeanShell has an invoke() method which you can use to implement arbitrary/missing methods. You could use it to implement something like this: bean() .id("one") .type(NamedBean) .name("first"); Notice I used "NamedBean" and not "NamedBean.class". BeanShell supports this, too. I used the BeanShell approach for the Dynaop configuration. Now for references to other beans, could you do something like this? bean() .id("one") .type(NamedBean) .name("first") .foo(singleton("foo")) // reference bean "foo" with singleton scope .bar(prototype("bar")) // reference bean "bar" with prototype scope .tee(bean("tee")); // reference bean "tee" with its default scope I'm really not a Spring fan to tell you the truth. It's bloated and the code is inefficient.
  6. Bob LeeDecember 02, 2005 @ 01:21 PM
    Thinking about it more... foo = bean(FooBean) // id is optional .name("Foo Bean") .singleton(); bean("bar", BarBean) .name("Bar Bean") .foo(foo) .prototype();
  7. twifkakDecember 17, 2005 @ 08:49 PM
    Yeah, I'd take the Builder route and use method_missing to simplify the above syntax. Also: class ::Module def const_mising(sym) sym end end though maybe you consider that too much of a hack...
  8. Online Purchasing StockApril 29, 2006 @ 12:35 AM
    I thout to do it in my local version...
  9. Process PurchasingApril 29, 2006 @ 11:00 AM
    The content of your show is great, I really enjoy it...
  10. 1942 Wheat PennyMay 04, 2006 @ 11:07 PM
    I thout to do it in my local version :(
  11. Movement Nausea Prescription MedicineMay 08, 2006 @ 02:57 PM
    I was very dissapointed of this.
  12. Thanks for taking the time to do it :(
  13. Prescription Music ReferenceMay 12, 2006 @ 01:44 AM
    I thout to do it in my local version :(