Hi
I want to have a pool of objects and instantiate them all when I deploy the application.
Here is the xml snippet where I declare the target bean, the pool and the proxy.
Below part of the code of the targetBean. Because I need some autowired stuff in the constructor, I used the @PostConstructor methodCode:<bean id="myTargetBean" class="package.TargetBean" scope="prototype" lazy-init="false"> </bean> <bean id="targetBeanPool" class="org.springframework.aop.target.CommonsPoolTargetSource" lazy-init="false"> <property name="targetBeanName" value="myTargetBean" /> <property name="minIdle" value="100" /> </bean> <bean id="myPoolFactory" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="targetSource" ref="targetBeanPool" /> </bean>
and ultimately, elsewhere in the code, I autowire the proxy to get the pooled objects.Code:public class TargetBean { private Client client; @PostConstruct private void postConstructor(){ //Some stuff log.debug("client instanciated : "+client); } public Client getClient() { return client; } }
This code works fine except that only one TargetBean is created when I start the application. I though minIdle would have solved the problem but apparently not.Code:@Autowired TargetBean myPoolFactory; Client client = myPoolFactory.getClient();
What did I miss ?
Thanks


Reply With Quote