Note that there are some explanatory texts on larger screens.

plurals
  1. POInjecting dependencies in a prototype bean
    text
    copied!<p>I am using lookup method injection in Spring 3 to inject a prototype bean into a singleton bean as described in the Spring docs <a href="http://docs.spring.io/spring/docs/2.5.x/reference/beans.html#beans-factory-method-injection" rel="nofollow">here</a>. Inside my prototype bean I have an <code>@Autowired</code> dependency on another bean declared in my applicationContext.xml. The lookup method injection seems to be working properly in that my prototype bean is being injected into my singleton bean, however, the prototype's dependency is not getting injected at all. Can dependencies be injected into the prototype bean in a normal way when the prototype is returned via lookup method? If not, what is the preferred way to do this?</p> <p><strong>Edit</strong>: The bean definitions are as follows:</p> <pre><code>&lt;bean id="jobRouter" class="com.ccn.JobRouter"&gt; &lt;lookup-method name="createJobConsumer" bean="jobConsumer"/&gt; &lt;/bean&gt; &lt;bean id="jobConsumer" class="com.ccn.JobConsumer" scope="prototype"/&gt; &lt;bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"&gt; &lt;property name="corePoolSize" value="5" /&gt; &lt;property name="maxPoolSize" value="100" /&gt; &lt;property name="WaitForTasksToCompleteOnShutdown" value="true" /&gt; &lt;/bean&gt; </code></pre> <p>JobRouter</p> <pre><code>public abstract class JobRouter { private LinkedHashMap&lt;String, JobConsumer&gt; jobRoutingMap = new LinkedHashMap&lt;String, JobConsumer&gt;(); public void add(Job Job) { if(!jobRoutingMap.containsKey(job.getObjectKey())){ jobRoutingMap.put(job.getObjectKey(), createJobConsumer()); } //Hand off job to consumer JobConsumer jobConsumer = jobRoutingMap.get(job.getObjectKey()); jobConsumer.add(job); } protected abstract JobConsumer createJobConsumer(); } </code></pre> <p>JobConsumer</p> <pre><code>public class JobConsumer { @Autowired private TaskExecutor taskExecutor; private LinkedBlockingQueue&lt;Job&gt; jobQueue = new LinkedBlockingQueue&lt;Job&gt;(); public JobConsumer() { taskExecutor.execute(new JobQueueMonitor()); } public boolean add(Job job) { if(!jobQueue.contains(job)){ return jobQueue.add(job); } return true; } private class JobQueueMonitor implements Runnable{ @Override public void run() { ... } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload