IllegalStateException: No Commons ObjectPool available

北慕城南 提交于 2019-12-13 03:19:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!