quartz 兩次執行問題


最近發現網站(xiayule.net)越寫越大,有些東西已經難以維護了,想要添加個功能,都得斟酌半天

項目中有很多可重構的地方,小重構一直進行,大的不敢動,畢竟沒有很多時間做測試。

最后,決定精簡代碼。。。。

能不用的框架、工具統統去掉,Struts慢慢用Spring MVC來代替,xml配置使用注解來代替。

狂改代碼一通后,着實覺得有些可惜,畢竟很多是自己費了很多心思的,幸虧有做筆記的習慣。

 

呃,言歸正傳,以下是筆記內容, 推薦直接看解決方案。

 

quartz 兩次執行問題是由於tomcat設置不當引起的,說白了,並非是 quartz 的原因,而是spring的配置被加載了兩遍。

 

為了能夠訪問網站根,即直接輸入http://localhost:8080就能訪問應用,我是這樣配置的tomcat

 

 <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">

<!--    <Engine name="Catalina" defaultHost="localhost">-->

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->

      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true" >

    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />
    <Context path="" docBase="getll" debug="0" reloadable="true"/>
  </Host>
</Engine>

 

關鍵是這一句

<Context path="" docBase="getll" debug="0" reloadable="true"/> 

其中 Context path="" 表明了網站的根, dacBase是我的項目打包目錄。這會導致我的web應用又被重新加載了一遍(webapps里面的項目本身就會被加載一遍),所以導致了項目中的bean都有兩份。

 

因此,嘗試另一種配置根目錄的方法。將項目放在webapps外的文件夾,然后指定其位置

<Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true"
        xmlValidation="false" xmlNamespaceAware="false">
        ......
        <Context path="" docBase="/home/tan/getllWebApp/getll"/>
</Host>

 

還有一點要注意,就是我的設置成 `<Context path="" docBase="/home/tan/getllWebApp/getll.war"/>` 無效,只能設置成解壓后的文件夾

 

第二天: 發現有時候應用程序不能啟動

解決方案:
鑒於前兩次的失敗,最后決定最終方案,刪除掉原先配置的<Context path="" docBase="/home/tan/getllWebApp/getll"/>, 如果沒有,就不用刪了,直接將應用解壓到 webapp/ROOT 里面(需刪除ROOT內的原內容)

一切解決,重復執行兩次的問題消失啦。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM