0

I'm trying to use Spring EL in XML config: Creating a task executor with queue-capacity from an existing beans ConfigProp.

<task:executor id="executorWithPoolSizeRange" 
               pool-size="#{ConfigProp.async.corePoolSize}-#{ConfigProp.async.maxPoolSize}"
               queue-capacity="#{ConfigProp.async.queueCapacity}"/>

From the Intellij IDEA, it's showing that pool-size can be resolved properly but not for queue-capacity, which is Integer type.

IDEA Complain message

Cannot convert string #{ConfigProp.async.queueCapacity} to target class java.lang.Integer"

Execution logs when run with Tomcat

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 129 in XML document from ServletContext resource [/WEB-INF/dispatcher-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 129; columnNumber: 69; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'task:executor'.
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:402) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]

What did I do wrong or is this not supported by SpringEL?

Thanh Nhan
  • 453
  • 6
  • 17
  • Regarding the "IDEA Complain message", it's not a problem of casting, I'm pretty sure that your property key is not replaced by the actual value behind it. As the message states, it tries to parse the string "#{ConfigProp.async.queueCapacity}" to an Integer. So check your properties setup, there are several options provided by Spring, i.e.PropertyPlaceholder. Might be a typo, so that the config key doesn't match the key in your properties file. – The Frozen One Jul 17 '20 at 07:49

1 Answers1

0

I could manually create a ThreadPoolTaskExecutor bean but it still not answer my question.

<beans:bean id="executorWithPoolSizeRange" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
        <beans:property name="corePoolSize" value="#{ConfigProp.async.corePoolSize}" />
        <beans:property name="maxPoolSize" value="#{ConfigProp.async.maxPoolSize}" />
        <beans:property name="queueCapacity" value="#{ConfigProp.async.queueCapacity}" />
    </beans:bean>
Thanh Nhan
  • 453
  • 6
  • 17