Spring Bean Initialization - Date passed as a string using xml, not working for step scope

I need to pass currentDate as a String to my sendMetaStatsTask tasklet added to the subject. Now, if I create a bean with scope = "step" using the following xml

<bean id="sendMetaStatsTask" class="org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter" scope="step">
        <property name="targetObject">
            <bean class="com.nextag.catalog.springbatch.tasklets.GenerateReportFromQueriesTasklet">
                <property name="mailTo" value="#{jobParameters['MAIL_TO']}"/>
                <property name="mailFrom" value="#{jobParameters['MAIL_FROM']?:'wizereporter@nextag.com'}"/>
                <property name="mailSubject" value="#{jobParameters['PARTNER_DOMAIN']+' Affiliate Seller Report - '+ currentDate.toString()}"/>
            </bean>
        </property>
        <property name="targetMethod" value="execute"/>
    </bean>

    <bean id="fastDateFormat" class="org.apache.commons.lang.time.FastDateFormat" factory-method="getInstance">
        <constructor-arg value="dd/MM/yyyy"/>
    </bean>

    <bean id="currentDate" class="java.util.Date" factory-bean="fastDateFormat" factory-method="format" scope="step">
        <constructor-arg>
            <bean class="java.util.Date"/>
        </constructor-arg>
    </bean>

He throws: -

bean 'currentDate', BeanDefinition [/home/nextag/Apache6/tomcat/webapps/nextag/WEB-INF/classes/META-INF/spring/batch/jobs/seller-meta-stats-logging-job.xml]: bean ; java.lang.IllegalStateException: - bean'scopedTarget.currentDate': .          org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)

, .

, , - ?

+4
1

- bean currentDate, .

<bean id="fastDateFormat" class="org.apache.commons.lang.time.FastDateFormat" factory-method="getInstance">        
        <constructor-arg value="dd/MM/yyyy"/>
    </bean>

    <bean id="currentDate" class="java.util.Date" factory-bean="fastDateFormat" factory-method="format" scope="step">
        <aop:scoped-proxy/>
        <constructor-arg>
            <bean class="java.util.Date"/>
        </constructor-arg>
    </bean>
+3

Source: https://habr.com/ru/post/1661529/


All Articles