Announcement Announcement Module
No announcement yet.
Inner inner beans Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Inner inner beans

    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 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:

    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!
    which works fine. The source code is below for completeness.

    Explanations appreciated. I wonder if this is a bug?

    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;

  • #2
    Inner classes should be seperated by a $ not by a . In general there shouldn't be a problem with inner inner classes (which aren't inner inner beans!!!)...


    • #3
      Thanks Marten.

      Yes that worked! A nasty little newbies gotcha.... nested properties should be seperated by the '.' character and nested classes by the '$', like the binary class names. It is in the documentation somewhere, I remember seeing it... but obviously only remembered after you'd told me the answer!