Spring @Scheduler正在执行两次。 我正在使用spring security,如果我删除上下文参数spring安全性不起作用

我在我的应用程序中使用spring Scheduler和spring security。 如果spring-servlet.xml文件在上下文参数中分配,则spring安全工作正常,但Spring Scheduler执行两次。 安全的context.xml

          <!--         -->                  

为spring-servlet.xml

                   com.joseph.model    org.hibernate.cfg.AnnotationConfiguration    ${jdbc.dialect} true                              

调度程序类

  package com.joseph.cronJob; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @Service public class SampleCronJobImpl implements SampleCronJob { private static int count=0; @Override @Scheduled(cron = "0 */1 * * * *") public void testSchedulerfunction() { count++; System.out.println("scheduler fuction call count: "+count); } } 

web.xml中

    CRUDWebAppMavenizedold  log4jConfigLocation classpath:log4j.xml   contextConfigLocation  /WEB-INF/security-context.xml,/WEB-INF/spring-servlet.xml    org.springframework.web.context.ContextLoaderListener   org.springframework.web.util.Log4jConfigListener   springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy   springSecurityFilterChain /*   spring org.springframework.web.servlet.DispatcherServlet 1   spring /   index.html index.htm index.jsp default.html default.htm default.jsp   

输出控制台

在此处输入图像描述

安全工作正常但调度程序执行两次为什么,我无法理解。 请帮助我。

谢谢

正如M.Deinum在评论中告诉你的那样,你正在双重加载根上下文。

在这里,您可以阅读有关mvc context / root context的更多信息。 网络中有更多关于它的信息

您必须创建一个新的config.xml,让我们将其命名为application-context或您喜欢的任何其他名称。 现在你必须使用spring-servlet.xml并将几乎所有内容移动到新的配置文件中,因此这两个文件都是这样的:

为spring-servlet.xml:

                               

应用-config.xml文件:

              com.joseph.model    org.hibernate.cfg.AnnotationConfiguration    ${jdbc.dialect} true         

web.xml中:

   CRUDWebAppMavenizedold  log4jConfigLocation classpath:log4j.xml   contextConfigLocation  /WEB-INF/security-context.xml,/WEB-INF/application-context.xml    org.springframework.web.context.ContextLoaderListener   org.springframework.web.util.Log4jConfigListener   springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy   springSecurityFilterChain /*   spring org.springframework.web.servlet.DispatcherServlet 1   spring /   index.html index.htm index.jsp default.html default.htm default.jsp