From: Solomon D. <sd...@gm...> - 2006-06-21 02:03:08
|
Bob, I invoked the entire code below a few times. The first execution was slow, but after that, the execution time was really quick (0-10 ms) using spring 2.0m5. What's your goal with this test? BTW, I wrote a home-grown wrapper around the Spring classes which runs at roughly the same speed. The equivalent Java code is: ProgrammableConfigurer configurer = new ProgrammableConfigurer() { protected void configure() { // "foo" definition BeanConfiguration foo = prototype("foo", Foo.class); foo.property("i", 5).property("s", "test"); foo.property("bar", ref("bar")).property("copy", ref("bar")); // "bar" definition BeanConfiguration bar = prototype("bar", BarImpl.class); bar.constructor().generic(ref("tee")).generic(5); // "tee" definition BeanConfiguration tee = prototype("tee", TeeImpl.class); tee.constructor().generic("test"); }; }; return (Foo) configurer.wire().getBean("foo"); -Solomon Duskis On 6/19/06, Bob Lee <cra...@cr...> wrote: > > Or can I tweak it to make it faster? > > DefaultListableBeanFactory beanFactory = new > DefaultListableBeanFactory(); > > // "tee" definition > RootBeanDefinition tee = new RootBeanDefinition(TeeImpl.class, > true); > tee.setLazyInit(true); > ConstructorArgumentValues teeValues = new > ConstructorArgumentValues(); > teeValues.addGenericArgumentValue("test"); > tee.setConstructorArgumentValues(teeValues); > > // "bar" definition > RootBeanDefinition bar = new RootBeanDefinition(BarImpl.class, > false); > ConstructorArgumentValues barValues = new > ConstructorArgumentValues(); > barValues.addGenericArgumentValue(new RuntimeBeanReference("tee")); > barValues.addGenericArgumentValue(5); > bar.setConstructorArgumentValues(barValues); > > // "foo" definition > RootBeanDefinition foo = new RootBeanDefinition(Foo.class, false); > MutablePropertyValues fooValues = new MutablePropertyValues(); > fooValues.addPropertyValue("i", 5); > fooValues.addPropertyValue("bar", new RuntimeBeanReference("bar")); > fooValues.addPropertyValue("copy", new RuntimeBeanReference("bar")); > fooValues.addPropertyValue("s", "test"); > foo.setPropertyValues(fooValues); > > beanFactory.registerBeanDefinition("foo", foo); > beanFactory.registerBeanDefinition("bar", bar); > beanFactory.registerBeanDefinition("tee", tee); > > Foo foo = (Foo) beanFactory.getBean("foo"); > > Here are the types I'm wiring: > > public class Foo { > > Bar bar; > Bar copy; > String s; > int i; > > public void setI(int i) { > this.i = i; > } > > public void setBar(Bar bar) { > this.bar = bar; > } > > public void setCopy(Bar copy) { > this.copy = copy; > } > > public void setS(String s) { > this.s = s; > } > } > > interface Bar { > > Tee getTee(); > int getI(); > } > > public class BarImpl implements Bar { > > final int i; > final Tee tee; > > public BarImpl(Tee tee, int i) { > this.tee = tee; > this.i = i; > } > > public Tee getTee() { > return tee; > } > > public int getI() { > return i; > } > } > > interface Tee { > > String getS(); > } > > public static class TeeImpl implements Tee { > > final String s; > > public TeeImpl(String s) { > this.s = s; > } > > public String getS() { > return s; > } > } > > > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer > |