Results 1 to 5 of 5

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

  1. #1
    Join Date
    Apr 2009
    Posts
    14

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

    Hi,
    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" />
    </beans:bean>

    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 at 04:10 PM.

  2. #2
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    Did you try that with Spring 3.0?

  3. #3
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    ...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. #4
    Join Date
    Apr 2009
    Posts
    14

    Default

    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"  
            class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
            <beans:property name="targetObject" ref="resourceManagerWrapper" />
            <beans:property name="targetMethod" value="getResource" />
            <beans:property name="arguments">
                <beans:list>
                    <beans:value>${batchConfig.resources.sourceDatabase}</beans:value>
                </beans:list>
            </beans:property>
        </beans:bean>
    But need some help that how can i call this method in the xml to get the data source?

  5. #5
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •