2017-05-08 8 views
0

私はQuartz SchedulerをSpring 4と統合しようとしていましたが、すべてのクラスが2回読み込まれていました。私はちょっと調べて、Dispatcherサーブレット・ローダーとContetxtListenerローダーの両方によるXML構成のロードのために起こることを知りました。エントリを削除すると問題が解決されます。しかし、私のweb.xmlには、そのようなエントリはありません。 私は間違っているかもしれない何かの助け?Spring 4コンテキストが2回ロードされました

EDITED: 私はQuratz Schedulerを使用してSPRINGの非常に基本的な実装にプロジェクトを縮小し、常に2回ロードします。クォーツスケジューラを通して呼び出されるアプリケーションには、クラス(POJO)が1つしかありません。 POJOは、オブジェクトのハッシュコードと現在時刻を示すメッセージをコンソールに表示します。メッセージは2つの異なるハッシュコードで同じ時間に2回印刷されます。 2つの異なるハッシュコードは、コンテキストの2つのロードをヒントします。

プロジェクト構造は以下の通りです: 更新のweb.xmlは

<?xml version="1.0" encoding="UTF-8"?> 
<web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 
<display-name>Spring MVC Application</display-name> 
<welcome-file-list> 
    <welcome-file>createIdeaPublic</welcome-file> 
    <welcome-file>index.html</welcome-file> 
    <welcome-file>index.htm</welcome-file> 
    <welcome-file>index.jsp</welcome-file> 
    <welcome-file>default.html</welcome-file> 
    <welcome-file>default.htm</welcome-file> 
    <welcome-file>default.jsp</welcome-file> 
</welcome-file-list> 
<display-name>Tractivity</display-name> 
<session-config> 
    <session-timeout>120</session-timeout> 
</session-config> 
    <servlet> 
    <servlet-name>Tractivity</servlet-name> 
    <servlet-class> 
     org.springframework.web.servlet.DispatcherServlet 
    </servlet-class> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
    <servlet-name>Tractivity</servlet-name> 
    <url-pattern>/</url-pattern> 
    </servlet-mapping> 
    <error-page> 
    <location>/jsp/components/jspError.jsp</location> 
</error-page> 
</web-app> 

と更新されたディスパッチャ・サーブレットXMLは以下のとおりである(無セッションリスナーで)以下の通りであるenter image description here

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:aop="http://www.springframework.org/schema/aop" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd 
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd "> 
<bean id="simpleJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> 
    <property name="targetObject" ref="quartzExample" /> 
    <property name="targetMethod" value="printMessage" /> 
</bean> 
<bean id="quartzExample" class="com.soft.quartz.QuartzExample"> 
</bean> 
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> 
    <property name="jobDetail" ref="simpleJobDetail" /> 
    <property name="cronExpression" value="0/3 * * * * ? *" /> 
</bean> 
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> 
    <property name="triggers"> 
     <list> 
      <ref bean="cronTrigger" /> 
     </list> 
    </property> 
</bean> 
</beans> 

クォーツスケジューラと呼ばれるPOJOの定義は、

です。
package com.soft.quartz; 

import java.util.Date; 

public class QuartzExample { 

    public void printMessage(){ 
     System.out.println("Hello Quartz "+this.hashCode()+" " + (new Date())); 
    } 

} 

このリリースのSpring jarファイルのバグですか?

+0

本当に2回読み込まれているのですか?間違ったログ設定がありますか?あなたのコードのどこにでも新しいApplicationContextを実行していません。 –

+0

奇妙なことに、いつでもcom.soft.utils.SessionListenerがSpringのContextLoaderListenerから拡張されていますか?もしそうなら、まずapplicationContext.xmlをロードしてからtractivity-servlet.xml – ootero

+0

本当に2回読み込まれます。 SessionListenerはContextLoaderListenerから継承されません。 私は質問を編集し、SessionListenerと他のものを削除しましたが、それでもコンテキストを2回読み込みます。 –

答えて

0

問題が解決しました。 EclipseのためのEclipseとTomcatのプラグインによるものです。 Eclipseの私のプロジェクト名はContextRootとは異なりました。 EclipseはアプリケーションをTomcatに一度デプロイしましたが、アプリケーションは2つのURL、つまりProjectNameとContext Rootの2つのURLからアクセスできます。

1)http://localhost:8080/TractivityPhase2/login - >プロジェクト名として

2)http://localhost:8080/Tractivity/login - >コンテキストルート

に関してので、実際にアプリケーションが2つのURLの二回ロードされます。

Context Rootを自分のプロジェクト名と同じにすると、私の問題は解決しました。この答えが他の人に役立つことを願っています。

+0

質問に回答を追加しないでください。質問を編集してください。 –

関連する問題