问题
In my project i use spring-boot
I have code like this
class ConfigurationUtils {
@Bean(name="retriver")
@Scope("prototype")
public Retriver retriver() {
Retriver dr = null;
try {
dr = new Retriver(config.getUserName(),
config.getPassword(),
config.getUrl());
} catch (Exception e) {
logger.error("Exepction in creating SOAP datasource connection");
}
return dr;
}
@Bean
public CommonsPool2TargetSource getRetriverPooledTargetSource() {
final CommonsPool2TargetSource commonsPoolTargetSource = new CommonsPool2TargetSource();
commonsPoolTargetSource.setTargetBeanName("Retriver");
commonsPoolTargetSource.setTargetClass(Retriver.class); //Getting error here....
commonsPoolTargetSource.setMaxSize(10);
return commonsPoolTargetSource;
}
@Bean
public ProxyFactoryBean proxyFactoryBean() {
ProxyFactoryBean p = new ProxyFactoryBean();
p.setTargetSource(getRetriverPooledTargetSource());
return p;
}
}
In my service class when I call as below
CommonsPool2TargetSource pool = configurationUtils.getRetriverPooledTargetSource();
dataRetriever = (DataRetriever) pool.getTarget();
System.out.println(" " + dataRetriever);
It throws below exception: What am i doing wrong here ?
Caused by: java.lang.IllegalStateException: No Commons ObjectPool available at org.springframework.util.Assert.state(Assert.java:73) at org.springframework.aop.target.CommonsPool2TargetSource.getTarget(CommonsPool2TargetSource.java:234) at com.spgmi.ca.prescore.actor.CompanyTransIndustryActor.preStart(CompanyTransIndustryActor.java:63) at akka.actor.Actor$class.aroundPreStart(Actor.scala:510) at akka.actor.UntypedActor.aroundPreStart(UntypedActor.scala:95) at akka.actor.ActorCell.create(ActorCell.scala:590) ... 9 more
来源:https://stackoverflow.com/questions/57093612/illegalstateexception-no-commons-objectpool-available