I have a Spring Integration directory poller:
This answer is based on the tip from Gary Russell in the comments above.
The reason for double-processing of files is that the root and web configs were both initialising file system listeners, and therefore processing each file twice.
My approach to avoiding having the file listeners in multiple contexts was as follows.
First define a web config which only picks up classes under the "web" package.
@Configuration
@ComponentScan(basePackages = { "com.myapp.web" })
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void configureDefaultServletHandling(
DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
Create separate root configs which only load beans which are not in the "web" package. i.e.
@Configuration
@ComponentScan(basePackages = { "com.myapp.services" })
public class ServicesConfig {
}
An additional factor in the configuration that took a little while to work out, was that my servlet filters and web security config needed to be in the 'root' context rather than the web context.