Spring 为带有@JobScope的类编写Junit测试用例时,错误为java.lang.IllegalStateException:没有为作用域名称注册作用域';工作';
执行测试用例时出错-没有为作用域名称“job”注册作用域 我的班级看起来像: 我的测试类看起来像:Spring 为带有@JobScope的类编写Junit测试用例时,错误为java.lang.IllegalStateException:没有为作用域名称注册作用域';工作';,spring,unit-testing,junit,Spring,Unit Testing,Junit,执行测试用例时出错-没有为作用域名称“job”注册作用域 我的班级看起来像: 我的测试类看起来像: 将@EnableBatchProcessing添加到测试类对我来说很有用。。。但我不确定你是否想把它放在测试课上。使用Config类并在测试类中导入配置可能更好 @TestExecutionListeners({DependencyInjectionTestExecutionListener.class, JobScopeTestExecutionListener.class }) @Enab
将@EnableBatchProcessing添加到测试类对我来说很有用。。。但我不确定你是否想把它放在测试课上。使用Config类并在测试类中导入配置可能更好
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, JobScopeTestExecutionListener.class })
@EnableBatchProcessing
@RunWith(SpringRunner.class)
public class JobServiceTest{
public JobExecution getJobExecution() {
JobExecution execution = MetaDataInstanceFactory.createJobExecution();
execution.getExecutionContext().putString("input.data", "foo,bar,spam");
return execution;
}
@Test
public void beforeJobTest() {
jobService.beforeJob(getJobExecution());
}
}
异常表示注释作业范围不存在。为什么要使用此批注?我正在使用@JobScope annotation获取jobparametersRename JobScope,例如在Job中,有两个spring批注的末尾有作用域:ApplicationScope、SessionScope。我认为spring会搜索所有以Scope结尾的注释,但我的逻辑中需要Jobscope。我还有其他带有stepscope的类,我面临着与没有为作用域名称'step'注册作用域相同的错误,只需重命名那些注释!
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, JobScopeTestExecutionListener.class })
@RunWith(SpringRunner.class)
public class JobServiceTest{
public JobExecution getJobExecution() {
JobExecution execution = MetaDataInstanceFactory.createJobExecution();
execution.getExecutionContext().putString("input.data", "foo,bar,spam");
return execution;
}
@Test
public void beforeJobTest() {
jobService.beforeJob(getJobExecution());
}
}
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, JobScopeTestExecutionListener.class })
@EnableBatchProcessing
@RunWith(SpringRunner.class)
public class JobServiceTest{
public JobExecution getJobExecution() {
JobExecution execution = MetaDataInstanceFactory.createJobExecution();
execution.getExecutionContext().putString("input.data", "foo,bar,spam");
return execution;
}
@Test
public void beforeJobTest() {
jobService.beforeJob(getJobExecution());
}
}