committed by
Mahmoud Ben Hassine
parent
ab9dbc3e93
commit
5fae33185f
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2013 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -63,7 +63,7 @@ import org.springframework.beans.factory.config.Scope;
|
||||
*/
|
||||
public class StepScope extends BatchScopeSupport {
|
||||
|
||||
private static final String TARGET_NAME_PREFIX = "stepScopedTarget.";
|
||||
private static final String TARGET_NAME_PREFIX = "scopedTarget.";
|
||||
|
||||
private Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,9 +16,12 @@
|
||||
|
||||
package org.springframework.batch.core.configuration.annotation;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
@@ -38,8 +41,6 @@ import org.springframework.context.annotation.ScopedProxyMode;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -101,6 +102,19 @@ public class StepScopeConfigurationTests {
|
||||
assertEquals("STEP", value.call());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.batch.core.configuration.xml.CoreNamespaceUtils#autoregisterBeansForNamespace
|
||||
*/
|
||||
@Test
|
||||
public void testStepScopeUsingNamespaceAutoregisterBeans() throws Exception {
|
||||
init(StepScopeConfigurationTestsUsingNamespaceAutoregisterBeans.class);
|
||||
|
||||
ISimpleHolder value = (ISimpleHolder) context.getBean("xmlValue");
|
||||
assertEquals("STEP", value.call());
|
||||
value = (ISimpleHolder) context.getBean("javaValue");
|
||||
assertEquals("STEP", value.call());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStepScopeWithProxyTargetClassInjected() throws Exception {
|
||||
init(StepScopeConfigurationInjectingProxy.class);
|
||||
@@ -198,7 +212,13 @@ public class StepScopeConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
public static class SimpleHolder {
|
||||
public static interface ISimpleHolder {
|
||||
|
||||
String call() throws Exception;
|
||||
|
||||
}
|
||||
|
||||
public static class SimpleHolder implements ISimpleHolder {
|
||||
|
||||
private final String value;
|
||||
|
||||
@@ -243,6 +263,18 @@ public class StepScopeConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ImportResource("org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTestsUsingNamespaceAutoregisterBeans-context.xml")
|
||||
public static class StepScopeConfigurationTestsUsingNamespaceAutoregisterBeans {
|
||||
|
||||
@Bean
|
||||
@StepScope
|
||||
protected SimpleHolder javaValue(@Value("#{stepExecution.stepName}") final String value) {
|
||||
return new SimpleHolder(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableBatchProcessing
|
||||
public static class StepScopeConfigurationInjectingProxy {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:batch="http://www.springframework.org/schema/batch"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd">
|
||||
|
||||
<bean id="tasklet"
|
||||
class="org.springframework.batch.core.configuration.annotation.StepScopeConfigurationTests$TaskletSupport" />
|
||||
|
||||
<batch:job id="job">
|
||||
<batch:step id="step1">
|
||||
<batch:tasklet ref="tasklet" />
|
||||
</batch:step>
|
||||
</batch:job>
|
||||
|
||||
<bean id="xmlValue"
|
||||
class="org.springframework.batch.core.configuration.annotation.StepScopeConfigurationTests.SimpleHolder"
|
||||
scope="step">
|
||||
<constructor-arg value="#{stepExecution.stepName}" />
|
||||
</bean>
|
||||
|
||||
<batch:job-repository id="jobRepository" />
|
||||
|
||||
<bean id="transactionManager"
|
||||
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
</beans>
|
||||
Reference in New Issue
Block a user