服务组件对象未加载到Spring Batch处理器中。但是这在春季测试中工作正常,请帮助我找到解决方案。
public class PersonJobProcessor implements ItemProcessor<Person,Person> {
@Autowired
PersonService service;
@Override
public Person process(final Person person) throws Exception {
//user service variable here
}
}
Error Message:-
Action:Consider defining a bean of type 'PersonService' in your configuration.
以下配置工作正常
@SpringBootTest
@RunWith(SpringRunner.class)
public class PersonServiceTest {
@Autowired
PersonService service;
public void testmethod(){
service.method();// works without issues
}
}
看起来 PersonJobProcessor 中缺少 SpringContext。您是否在本课程中添加了@Component?