Spring 批处理 JUnit 5 JobLauncherTestUtils 未初始化
Spring Batch JUnit 5 JobLauncherTestUtils is not initialized
我正在尝试在 JUnit 5 和 SpringBatchTest 注释中加载 JobLauncherTestUtils 对象。但是,它无法加载应用程序上下文。所有其他自动装配的 bean 加载成功,但 JobLauncherTestUtils 加载失败。这是我的测试配置,省略了导入。我尝试在 BeforeAll 中手动加载它,但随后 JobRepository 和 JobLauncher 无法加载。我只对能够成功实例化 JobLauncherTestUtils 感兴趣。请帮忙!
@ExtendWith(SpringExtension.class)
@ExtendWith(MockitoExtension.class)
@SpringBatchTest
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class ,
DirtiesContextTestExecutionListener.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@EnableAutoConfiguration
public class ProductsProcessorTest {
@Autowired
JobLauncherTestUtils jobLauncherTestUtils;
@Autowired
private JobRepositoryTestUtils jobRepositoryTestUtils;
@MockBean
JobLauncher jobLauncher;
@Autowired
JobRepository jobRepository;
@Autowired
OrderManagementService orderManagementService;
@MockBean
Job keyLoaderJob;
@Autowired
@JobScope
static ProductsLoader productsLoader;
//Tried manually instantiating it, but then would l
@BeforeAll
static void setUp() throws Exception {
//jobLauncherTestUtils = new JobLauncherTestUtils();
}
//This does not work either
@BeforeEach
void init(){
// jobLauncherTestUtils.setJobLauncher(jobLauncher);
// jobLauncherTestUtils.setJobRepository(jobRepository);
}
....
}
这是我得到的异常:
原因:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为 'jobLauncherTestUtils' 的 bean 时出错:通过方法 'setJobRepository' 参数 0 表达的不满足的依赖关系;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:没有可用类型 'org.springframework.batch.core.repository.JobRepository' 的符合条件的 bean:预计至少有 1 个符合自动装配候选条件的 bean。依赖注解:{}
No qualifying bean of type 'org.springframework.batch.core.repository.JobRepository' available
此错误意味着在您的测试应用程序上下文中没有定义 JobRepository
bean。确保导入定义此 bean 的 class。
我正在尝试在 JUnit 5 和 SpringBatchTest 注释中加载 JobLauncherTestUtils 对象。但是,它无法加载应用程序上下文。所有其他自动装配的 bean 加载成功,但 JobLauncherTestUtils 加载失败。这是我的测试配置,省略了导入。我尝试在 BeforeAll 中手动加载它,但随后 JobRepository 和 JobLauncher 无法加载。我只对能够成功实例化 JobLauncherTestUtils 感兴趣。请帮忙!
@ExtendWith(SpringExtension.class)
@ExtendWith(MockitoExtension.class)
@SpringBatchTest
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class ,
DirtiesContextTestExecutionListener.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@EnableAutoConfiguration
public class ProductsProcessorTest {
@Autowired
JobLauncherTestUtils jobLauncherTestUtils;
@Autowired
private JobRepositoryTestUtils jobRepositoryTestUtils;
@MockBean
JobLauncher jobLauncher;
@Autowired
JobRepository jobRepository;
@Autowired
OrderManagementService orderManagementService;
@MockBean
Job keyLoaderJob;
@Autowired
@JobScope
static ProductsLoader productsLoader;
//Tried manually instantiating it, but then would l
@BeforeAll
static void setUp() throws Exception {
//jobLauncherTestUtils = new JobLauncherTestUtils();
}
//This does not work either
@BeforeEach
void init(){
// jobLauncherTestUtils.setJobLauncher(jobLauncher);
// jobLauncherTestUtils.setJobRepository(jobRepository);
}
....
}
这是我得到的异常:
原因:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为 'jobLauncherTestUtils' 的 bean 时出错:通过方法 'setJobRepository' 参数 0 表达的不满足的依赖关系;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:没有可用类型 'org.springframework.batch.core.repository.JobRepository' 的符合条件的 bean:预计至少有 1 个符合自动装配候选条件的 bean。依赖注解:{}
No qualifying bean of type 'org.springframework.batch.core.repository.JobRepository' available
此错误意味着在您的测试应用程序上下文中没有定义 JobRepository
bean。确保导入定义此 bean 的 class。