Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

java - Scope 'step' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton

In my application I want to create some beans in scope step. I have a problem with entityManagerFactory it gives me this error: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.scopedTarget.entityManagerFactory': Scope 'step' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No context holder available for step scope

here is the way i am creating the beans.

<context:property-placeholder />
<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource" scope="step">
    <aop:scoped-proxy/>
    <property name="driverClassName" value="#{jobExecutionContext.get('batchProperties').getProperty('database.driverClass')}" />
    <property name="url" value="#{jobExecutionContext.get('batchProperties').getProperty('database.url')}" />
    <property name="username" value="#{jobExecutionContext.get('batchProperties').getProperty('database.user')}" />
    <property name="password" value="#{jobExecutionContext.get('batchProperties').getProperty('database.password')}" />
</bean>

<bean id="jpaVendorAdapter"
    class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter" scope="step">
    <aop:scoped-proxy/>
    <property name="databasePlatform"
        value="org.eclipse.persistence.platform.database.PostgreSQLPlatform" />
    <property name="generateDdl" value="false" />
    <property name="showSql" value="true" />
</bean> 

aop:scoped-proxy/

<bean id="stepScope" class="org.springframework.batch.core.scope.StepScope">
    <property name="autoProxy" value="true" />
</bean>

<batch:job id="jobAccountDemo3456111" job-repository="jobRepository"
    restartable="true">
    <batch:step id="jobAccountDemo3456111.step1" parent="abstractParentStep">
         
        <batch:tasklet>
        <batch:listeners>
            <batch:listener ref="loadPropertiesListener" />
        </batch:listeners>
            <batch:chunk reader="importAccountJobResourceReader" />
        </batch:tasklet>
    </batch:step>
</batch:job>

  <bean id="loadPropertiesListener" class="com.kmse.hicp.bof.batch.preset.gen.jpa.imports.PropertyLoaderJobExecutionListener" scope="step">
    <property name="pfb">
        <bean class="org.springframework.beans.factory.config.PropertiesFactoryBean">
            <property name="location" value="file:#{jobParameters['myfile']}" />
        </bean>
    </property>
 </bean>

is there a way to solve this problem


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...