Spring 解決定時任務執行兩次的問題

第一種情況可能是spring掃描了兩次
比如spring-config\spring-mvc都掃描了改定時任務,則更改spring-mvc配置的掃描路徑過濾定時調度

<context:component-scan base-package="com.test">
        <context:exclude-filter type="annotation" expression="org.springframework.scheduling.annotation.EnableScheduling"/>
    </context:component-scan>

第二種情況可能是tomcat配置導致容器被初始化兩次
由于web項目直接放在tomcat的webapp下,并且通過根路徑訪問,配置如下
<Context path="" docBase="..\.." debug="0" reloadable="true"/>

查找類似問題處理方式:
方法1:在conf/Catalina/localhost生成test.xml【推薦】

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
    <Context antiResourceLocking="false" privileged="true" useHttpOnly="true" path="/" docBase="..\.." >
  <!--
    Remove the comment markers from around the Valve below to limit access to
    the manager application to clients connecting from localhost
  -->
  <!--
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
  -->
</Context>

方法2:不配置根路徑訪問
方法3:將路徑已出webapp目錄,在docBase中指定路徑(可以是相對于webapp的路徑,或者絕對路徑)
方法4:替換ROOT目錄

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • Spring Cloud為開發人員提供了快速構建分布式系統中一些常見模式的工具(例如配置管理,服務發現,斷路器,智...
    卡卡羅2017閱讀 134,981評論 19 139
  • Spring Boot 參考指南 介紹 轉載自:https://www.gitbook.com/book/qbgb...
    毛宇鵬閱讀 46,970評論 6 342
  • 從三月份找實習到現在,面了一些公司,掛了不少,但最終還是拿到小米、百度、阿里、京東、新浪、CVTE、樂視家的研發崗...
    時芥藍閱讀 42,372評論 11 349
  • 這些屬性是否生效取決于對應的組件是否聲明為 Spring 應用程序上下文里的 Bean(基本是自動配置的),為一個...
    發光的魚閱讀 1,449評論 0 14
  • 就像無聲的影片,沒有做過多的追究,仿佛一切意義只存在眼睛里,沒有絲毫聽取的能力。猶如一個世紀那么久,以前做的所有努...
    董落憂閱讀 198評論 0 1