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内的原内容)

一切解决,重复执行两次的问题消失啦。

 

posted on 2014-12-05 19:19  Still_Raining  阅读(7410)  评论(1编辑  收藏  举报