I am creating an @Scheduled
task to run every 5 seconds. As has been a problem in other questions, my task is running twice!
I have looked at other ques
I also had this problem. I am using Spring 4. I have no xml configuration. Everything is configured with annotations and Java config.
I have a base configuration and a WebConfiguration. the error was caused by using @ComponentScan in both configurations. I removed component scan from base configuration.
@EnableWebMvc
@ComponentScan(basePackages = { "com.myservice" })
@Configuration
public class WebConfiguration extends WebMvcConfigurerAdapter {
@Bean
public UrlBasedViewResolver setupViewResolver() {
UrlBasedViewResolver resolver = new UrlBasedViewResolver();
resolver.setPrefix("/WEB-INF/jsp/");
resolver.setSuffix(".jsp");
resolver.setViewClass(JstlView.class);
return resolver;
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
@Configuration
@EnableScheduling
//@ComponentScan(basePackages = { "com.myservice" })
@PropertySource("${myservice.properties.location:classpath:myservice.properties}")
public class BaseConfiguration {
@Autowired
Environment environment;
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
return new PropertySourcesPlaceholderConfigurer();
}