我将 Spring Boot1.4.0.RELEASE与spring-boot-starter-batch,spring-boot-starter-aop和spring-retry
我有一个 Spring 集成测试,其中有一个@Service在运行时被模拟的。我注意到,如果该类在其方法上@Service包含任何@Retryable注释,那么它似乎会干扰Mockito.verify(),我得到一个UnfinishedVerificationException. 我想这一定与什么有关spring-aop?如果我注释掉@Retryable中的所有注释,@Service则验证工作再次正常。
我创建了一个github 项目来演示这个问题。
它失败sample.batch.MockBatchTestWithRetryVerificationFailures.batchTest()于validateMockitoUsage();
像这样的东西:
12:05:36.554 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - After test method: context [DefaultTestContext@5ec0a365 testClass = MockBatchTestWithRetryVerificationFailures, testInstance = sample.batch.MockBatchTestWithRetryVerificationFailures@5abca1e0, testMethod = batchTest@MockBatchTestWithRetryVerificationFailures, testException = org.mockito.exceptions.misusing.UnfinishedVerificationException:
Missing method call for verify(mock) here:
-> at sample.batch.service.MyRetryService$$FastClassBySpringCGLIB$$7573ce2a.invoke(<generated>)
Example of correct verification:
verify(mock).doSomething()
Run Code Online (Sandbox Code Playgroud)
不过,我有另一个类( ) ,它带有一个没有任何注释的sample.batch.MockBatchTestWithNoRetryWorking.batchTest()模拟类,并且验证工作正常。 …
所以我在 Spring Batch3.0.7.RELEASE和 Spring4.3.2.RELEASE中有一个问题,我们想prototype在使用并发时使用 ItemProcessor的范围。
请参阅appBatchCreationProcessor()和BatchCreationStep(),我已尝试确定 的范围appBatchCreationProcessor prototype,但它似乎没有任何效果,所有 10 个线程都使用相同的项目处理器。
有没有解决的办法?或者这是设计使然?
AppBatchConfiguration.java
@Configuration
@EnableBatchProcessing
@ComponentScan(basePackages = "our.org.base")
public class AppBatchConfiguration {
private final static SimpleLogger LOGGER = SimpleLogger.getInstance(AppBatchConfiguration.class);
private final static String OUTPUT_XML_FILE_PATH_PLACEHOLDER = null;
private final static String INPUT_XML_FILE_PATH_PLACEHOLDER = null;
@Autowired
public JobBuilderFactory jobBuilderFactory;
@Autowired
public StepBuilderFactory stepBuilderFactory;
@Bean(name = "cimAppXmlReader")
@StepScope
public <T> ItemStreamReader<T> appXmlReader(@Value("#{jobParameters[inputXmlFilePath]}")
String inputXmlFilePath) {
LOGGER.info("Job Parameter => App XML File Path …Run Code Online (Sandbox Code Playgroud)