简体   繁体   中英

Spring Integration SFTP - Reuse existing task scheduler

I have a problem when using this line in my context.xml

<int:channel id="ftpChannel"/>

It throws this error

Could not autowire field: private org.springframework.core.task.TaskExecutor com.test.service.MyServices.taskExecutor; 
nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.core.task.TaskExecutor] is defined: expected single matching bean but found 2: myOwnScheduler,taskScheduler

It seems like the channel create its own task scheduler and it troubles my autowired properties

@Autowired(required = false)
private TaskExecutor taskExecutor;

So how can I make the channel reuse back my own scheduler, instead of creating a new one ? Or is there any suggestion to fix this ?

I'm using Spring Integration v4.0.0.

You have two bean (with the following names: myOwnScheduler, taskScheduler) of type TaskExecutor so spring can't decide which one to use. So he throws this exception. You need to use a qualifier like this:

@Qualifier("myOwnScheduler")
@Autowired(required = false)
private TaskExecutor taskExecutor;

You seem to be confusing TaskScheduler and TaskExecutor . The framework provides a default scheduler (bean name taskScheduler ), but not an executor.

Documentation here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM