IllegalStateException:没有可用的Commons ObjectPool

时间:2019-07-18 11:39:44

标签: java spring-boot pool

在我的项目中,我使用spring-boot

我有这样的代码

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 RetriverPooledTargetSource() {
        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(RetriverPooledTargetSource());
        return p;
    }

}

在我的服务班级中,如下所示致电

CommonsPool2TargetSource pool  = configurationUtils.dataRetrieverPooledTargetSource();

    dataRetriever  = (DataRetriever) pool.getTarget();
    System.out.println(" " + dataRetriever);

它引发以下异常:我在这里做什么错了?

由于:java.lang.IllegalStateException:没有可用的Commons ObjectPool     在org.springframework.util.Assert.state(Assert.java:73)     在org.springframework.aop.target.CommonsPool2TargetSource.getTarget(CommonsPool2TargetSource.java:234)     在com.spgmi.ca.prescore.actor.CompanyTransIndustryActor.preStart(CompanyTransIndustryActor.java:63)     在akka.actor.Actor $ class.aroundPreStart(Actor.scala:510)     在akka.actor.UntypedActor.aroundPreStart(UntypedActor.scala:95)     在akka.actor.ActorCell.create(ActorCell.scala:590)处     ...还有9个

0 个答案:

没有答案