Hi,
I know this question may sound silly for some of you but I am new to Spring and I would like to learn the best practices of this powerful framework.
I have the following class that produce a list of objects:
and then I have this other class that should use the list of objects :Code:@Component public class DataProducer implements ProducerInterface{ public List<ResultObject> getData(String param) { .... } }
I would like to inject the producer into the consumer but I can't find the best way of doing it. I would like to build something like (ES from a main)Code:@Component public class DataConsumer implements ConsumerInterface{ private List<ResultObject> data; @Inject public void setData(List<ResultObject> data) { this.data=data; } public void consumeData() { .... } }
But the way I have shown you doen't work. One of the problems is that I don't know how to pass the String param to the DataProducer.getData(String param) method!Code:String param = args[0]; ConsumerInterface consumer = (ConsumerInterface)ctx.getBean(ConsumerInterface.class); consumer.consumeData();
The second thing is that the Injection does not work and the consumer and the producer are not tied.
Can someone help?
thank you.


Reply With Quote