Announcement Announcement Module
No announcement yet.
Problem using #{jobExecutionContext[${batchConfig.resources.sourceDatabase}]} Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem using #{jobExecutionContext[${batchConfig.resources.sourceDatabase}]}

    I am using Spring Batch 2.0.0 and try to use the late binding feture to load the data source through execution context. Here is the bean defination -

    <beans:bean id="testSRC" class="org.springframework.orm.ibatis.SqlMapClient FactoryBean">
    <beansroperty name="dataSource" value="#{jobExecutionContext[${batchConfig.resources.sourceDatabase}]}" />
    <beansroperty name="configLocation" value="ibatis-config.xml" />

    The data source is fetched from JNDI resource and loaded in execution context with Job listener in beforeStart().

    When I run this batch I get following error -
    HTML Code:
    org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] 
    to required type [javax.sql.DataSource] for property 'dataSource'; 
    So is it means that through late binding only String can be passed?
    Last edited by vinvh; Mar 12th, 2010, 04:10 PM.

  • #2
    Did you try that with Spring 3.0?


    • #3
      ...and by the way: it's not a great idea to put a DataSource in an ExecutionContext (it may be Serializable, but I wouldn't want to rely on it). There must be a better way.


      • #4
        Thanks Dave,
        Actually Datasource is just one example. There will be other type of objects I want to handle through this feature.

        I am trying this with Spring Batch 2.0 and Spring 2.5 as these are stable release.

        Other option i am trying with the help of org.springframework.beans.factory.config.MethodInv okingFactoryBean to get through a wrapper class.

        HTML Code:
        <beans:bean id="resources"  
                <beans:property name="targetObject" ref="resourceManagerWrapper" />
                <beans:property name="targetMethod" value="getResource" />
                <beans:property name="arguments">
        But need some help that how can i call this method in the xml to get the data source?


        • #5
          Try <ref bean="${...}"/> in your list. If your ResourceManagerWrapper could be refactored so the dependency can be injected normally that would be much easier to use and to read. This is basic Spring DI stuff, so maybe you should hang out in the Spring Framework forum for a bit and do some reading on that?