neoeahit
neoeahit

Reputation: 1799

Specifying Constructor Arg for GenericKeyed Pool( Apache Commons)

I am trying to inject values using spring config: but i am getting this error

Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)

The Spring code snippet is:

<bean id="Pool" class="org.apache.commons.pool.impl.GenericKeyedObjectPool">
        <constructor-arg name = "factory" ref="xyzFactory" />
        <constructor-arg type = "int" name = "maxActive" value='3' />
        <constructor-arg type= "byte" name = "whenExhaustedAction" value='WHEN_EXHAUSTED_GROW' />       
        <constructor-arg type = "long" name = "maxWait" value='3000' />
        <constructor-arg type = "int" name = "maxIdle" value='3' />
        <constructor-arg name = "testOnBorrow" value='true' />
        <constructor-arg name = "testOnReturn" value='true' />
    </bean>

Please Advice?

Upvotes: 0

Views: 348

Answers (2)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 280112

With this

<constructor-arg type= "byte" name = "whenExhaustedAction" value='WHEN_EXHAUSTED_GROW' />       

Spring will try to convert the String value "WHEN_EXHAUSTED_GROW" to a byte and fail.

You should be able to use <util:constant>

<constructor-arg type= "byte" name = "whenExhaustedAction" />     
    <util:constant static-field="org.apache.commons.pool.impl.GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW"/>
</constructor-arg>

To resolve the value of the static field. Don't forget to add the corresponding namespace to your xml context.


Please be consistent and use double quotes on your attribute values.

Upvotes: 1

cowls
cowls

Reputation: 24344

Couple of things to check:

WHEN_EXHAUSTED_GROW is that a byte value? Doesnt look like it, maybe that needs to be a referenced bean or something

<constructor-arg name = "testOnBorrow" value='true' />
<constructor-arg name = "testOnReturn" value='true' />

Add the type=boolean to these

And check xyz factory correctly implements KeyedPoolableObjectFactory

Upvotes: 0

Related Questions