Q:

autowired vaadin component gets index -1

I use vaadin-spring. I created public abstract class AbstractBasicVerticalLayoutWithMenu extends HorizontalLayout implements View and I have two normal classes extending it. In abstract class I @Autowire Menu component defined: 
@UIScope
@SpringComponent
public class Menu extends CssLayout
both classes are annotated 
@UIScope
@SpringView
I have very strange issue in one of views, that my menu component is not being displayed. 
I did some digging and added logging. On 
@Override
    public void enter(ViewChangeEvent event)
method I added logging and tried many thigs and I found that when I do  this.getComponentIndex(menu) that wrong view component has index -1! 
Interesting thing is that if I remove correctly displayed view from navigator (i do it: getNavigator().addView(FirstTesterView.VIEW_NAME, firstTesterView);) then this incorrect view is back to correct. 
I have no idea why, but it looks like only first of instantiated classes extending acstract gets @Autowired component but not next.  
What do I do wrong? 

A:

Index -1 means that the component was not found among the children.
Now, if your component is singleton, which is the default scope for a spring bean, then you always get the same instance. Furthermore, a Vaadin component can only have one parent at any given time, so probably you've missed some IllegalStateException in the log.
To fix this, you can set the scope of your menu to prototype so you get a new instance each time.

