Я добавил
@Bean
@DependsOn("fileInputChannel")
@ServiceActivator(inputChannel = "errorChannel",
outputChannel = "nullChanel")
protected ErrorLogger errorLogger(JobLauncher jobLauncher) {
return new ErrorLogger();
}
и
public class ErrorLogger {
private static final Logger logger =
LoggerFactory.getLogger(ErrorLogger.class);
@Autowired
private SourcePollingChannelAdapter fileInputChannel;
@ServiceActivator
public void logError(Message<JobExecution> message) {
JobExecution msgex=message.getPayload();
if (msgex.getStatus() == BatchStatus.FAILED) {
logger.error("Exception " +
msgex.getExitStatus().getExitDescription());
fileInputChannel.stop();
}
}
}
Но я получаю ошибку автопроводки в ErrorLogger
Unsatisfied dependency expressed through field 'fileInputChannel'; nested
exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type
'org.springframework.integration.endpoint.SourcePollingChannelAdapter'
available:
Похоже, проблема порядка инициализации несмотря на @DependsOn ("fileInputChannel") , потому что я могу автоматически загружать его в отдельный контроллер без ошибок.
Работает только с
@Autowired(required = false)
private SourcePollingChannelAdapter fileInputChannel;