Spring @Scheduled task runs twice

后端 未结 3 1332
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-11 09:05

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

3条回答
  •  悲&欢浪女
    2020-12-11 09:49

    I believe this is caused by same config file being loaded twice in your web.xml

    
        servlet
        org.springframework.web.servlet.DispatcherServlet
    
        contextConfigLocation
        /WEB-INF/spring_config.xml 
        
        1
    
    
    
        contextConfigLocation
        /WEB-INF/spring_config.xml 
    
    

    EDIT To fix it:

    Create another file servlet-servlet.xml (this will be picked up by the ServletDispatcher config by default since it matches the file by servlet name) The file will contain this:

    
        
        
        
    
    

    Modify the original file (spring-config.xml):

    
        
        
        
        
        
    
    

    Modify your web xml servlet config to following:

    
        servlet
        org.springframework.web.servlet.DispatcherServlet
        1
    
    

提交回复
热议问题