Hello Spring forum,
First time post here. Just learning Spring "properly" for the first time..
Is is possible to have inner inner beans in Spring? I assumed it was from the documentation yet Spring cannot successfully parse the following and I see a ClassNotFoundException
Caused by: java.lang.ClassNotFoundException: com.js.springtest.beans.NestedPropertyBean.EggCup. Egg
in the stack trace. My domain model is
NestedPropertyBean -> top level class
EggCup -> nested top level (static) class inside NestedPropertyBean
Egg -> nested top level (static) class inside EggCup
this parses ok..
<bean id="innerBeanBean" class="com.js.springtest.beans.NestedPropertyBean" >
</bean>
<bean id="eggCupBean" class="com.js.springtest.beans.NestedPropertyBean. EggCup"></bean>
but not this...
<bean id="eggBean" class="com.js.springtest.beans.NestedPropertyBean. EggCup.Egg"></bean>
Yet in Java you can do something like this:
which works fine. The source code is below for completeness.Code:package com.js.springtest.beans; public class TestNestedBeans { public static void main(String[] args) { NestedPropertyBean npb = new NestedPropertyBean(); NestedPropertyBean.EggCup eggCup = new NestedPropertyBean.EggCup(); NestedPropertyBean.EggCup.Egg egg= new NestedPropertyBean.EggCup.Egg();//look ma no compile errors! } }
Explanations appreciated. I wonder if this is a bug?
Regards,
John
Code:package com.js.spring.test.beans; public class NestedPropertyBean { public static class EggCup{ public static class Egg{ private int size; public int getSize() { return size; } public void setSize(int size) { this.size = size; } } private Egg egg = new Egg(); public int getSize(){ return this.egg.size; } public Egg getEgg() { return egg; } public void setEgg(Egg egg) { this.egg = egg; } } private EggCup eggCup = new EggCup(); public int getSize(){ return this.eggCup.getSize(); } public EggCup getEggCup() { return eggCup; } public void setEggCup(EggCup eggCup) { this.eggCup = eggCup; } }


Reply With Quote