Announcement Announcement Module
Collapse
No announcement yet.
Injecting "Selected/Qualified" List of Beans using Autowire or other mechanism Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Injecting "Selected/Qualified" List of Beans using Autowire or other mechanism

    Hello,
    Sorry was taking a hiatus from then Spring world into the OSGi world for the last year and half. Got badly burnt by IBM tools but than thats an another story! If some has already answered this question or there is an obvious answer please pardon me.

    I'm implementing composite pattern via autowiring/annotations. For instance I have an interface called Module that represents the leaf on the composite pattern and Sequencer that represents the composite which inturn is a subtype of Module

    I want to create two instances of a class called Seuqencer (The composite) SequencerA and SequncerB

    With Annotations the only way I could inject a list of beans of type Module (selected list) is as follows: Wondering if there is any other way?

    Code:
    @Component("sequencerB")
    public class SequencerB extends AbstractSequencer {
    	@Configuration ("sequenerBConfig")
    	static public class SequencerBConfigEmbedded {
    		private @Value("#{moduleC}") Module moduleC;
    		private @Value("#{moduleD}") Module moduleD;
    
    		@Bean
    		  public List<Module> sequencerBModules() {
    			List<Module> modules = new LinkedList<Module>();
    			modules.add (moduleC);
    			modules.add (moduleD);
    		    return modules;
    		  }		
    	}
    	
    	@Value("#{sequencerBModules}")
    	private List <Module> modules;
    Here the SequencerB instance is injected with a list of Beans of type Module(leaf) but only instances ModuleC and ModuleD. SequencerA may be injected with a list of Modules (ModuleA and ModuleB).

    Is there any simple way of doing this without XML? Some thing as follows would have been nice!

    Code:
    @Values("#{ModuleC}, #{ModuleD}")
    	private List <Module> modules;
    Please note that tag it is @Values and not @Value (Of course @Values annotation does not exist). I'm looking for something similar/simple to the above?

    Any ideas please?

    Thanks in advance!

    Matt

  • #2
    Hello,
    Anybody out there please?

    Thanks
    Matt

    Comment

    Working...
    X