我想实现CommonsPoolTargetSource,但我无法弄清楚我需要做什么才能让它在开始时创建我的最小对象?通过阅读文档我在我的应用程序配置中应该是我需要开始,但测试表明,池是零而不是我设置的最小值是4.CommonsPoolTargetSource不会创建对象
这是我的应用程序配置:
@Configuration
@PropertySource({"classpath:config.properties"})
@ComponentScan(basePackages = {"com.mf.bb"})
public class AppConfig {
@Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasenames("classpath:i18n/messages");
messageSource.setUseCodeAsDefaultMessage(true);
messageSource.setDefaultEncoding("UTF-8");
messageSource.setCacheSeconds(0);
return messageSource;
}
@Bean
public static PropertySourcesPlaceholderConfigurer propertyPlaceHolderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
@Bean
@Scope("prototype")
public BBIDSApp bbIDSApp() {
return new BBIDSApp();
}
@Bean
public CommonsPoolTargetSource commonsPoolTargetSource() {
CommonsPoolTargetSource commonsPoolTargetSource = new CommonsPoolTargetSource();
commonsPoolTargetSource.setMinIdle(4);
commonsPoolTargetSource.setMaxSize(50);
commonsPoolTargetSource.setTargetBeanName("bbIDSApp");
commonsPoolTargetSource.setTargetClass(BBIDSApp.class);
System.err.println("I'm alive!!!");
return commonsPoolTargetSource;
}
@Bean
public ProxyFactoryBean proxyFactoryBean() {
ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
proxyFactoryBean.setTargetSource(commonsPoolTargetSource());
return proxyFactoryBean;
}
@Bean
public MethodInvokingFactoryBean poolConfigAdvisor() {
MethodInvokingFactoryBean poolConfigAdvisor = new MethodInvokingFactoryBean();
poolConfigAdvisor.setTargetObject(commonsPoolTargetSource());
poolConfigAdvisor.setTargetMethod("getMaxIdle");
return poolConfigAdvisor;
}
}