1

DAOのリモートロケーションからxmlファイルを読み取ろうとしています。

<bean id="queryDAO"
      class="com.contextweb.openapi.commons.dao.reporting.impl.QueryDAOImpl">
  <property name="dataSource" ref="myDS"/>
  <property name="inputSource" ref="xmlInputSource"/>
</bean>

<bean id="fileInputStream" class="java.io.FileInputStream">
  <constructor-arg index="0" type="java.lang.String"
                   value="${queriesFileLocation}"/>
</bean>
<bean id="xmlInputSource" class="org.xml.sax.InputSource">
  <constructor-arg index="0" >
    <ref bean="fileInputStream"/>
  </constructor-arg>
</bean>

初めてXMLを読むことができます。以降のリクエストでは、inputstreamが使い果たされます。

4

3 に答える 3

2

春には、デフォルトですべてのBeanオブジェクトがシングルトンであることをご存知だと思います。singleton="false"したがって、これらのBean宣言のフィールドを設定して、fileInputStreamとxmlInputSourceを非シングルトンとして言及してみてください。

于 2012-08-07T07:53:03.393 に答える
1

あなたはFileInputStream問題があるところにそれを使っています。ストリーム内のデータを一度読み取った後は、コンテンツを再度読み取ることはできません。ストリームは終了しました。

BufferedInputStreamこの問題の解決策は、ファイル内の任意の場所を指すストリームのリセットをサポートする別のクラスを使用することです。

次の例は、BufferedInputStreamが1回だけ開かれ、ファイルを複数回読み取るために使用できることを示しています。

BufferedInputStream bis = new BufferedInputStream (new FileInputStream("test.txt"));

        int content;
        int i = 0;

        while (i < 5) {

            //Mark so that you could reset the stream to be beginning of file again when  you want to read it.
            bis.mark(0);

            while((content = bis.read()) != -1){

                //read the file contents.
                System.out.print((char) content);
            }
                System.out.println("Resetting ");
                bis.reset();
                i++;

        }

    }

キャッチがあります。このクラスを自分で使用しているのではなく、使用に依存しているため、このクラスを拡張しorg.xml.sax.InputSourceて独自のクラスを作成し、ファイルを開始するストリームに メソッド をオーバーライドする必要があります。InputSourcegetCharacterStream()getByteStream()mark() reset()

于 2012-08-07T14:14:42.060 に答える
0

おそらく、FileInputStreamをインライン化して、毎回新しいインスタンスを強制するようにすることができますか?

<bean id="queryDAO" class="com.contextweb.openapi.commons.dao.reporting.impl.QueryDAOImpl">
    <property name="dataSource" ref="contextAdRptDS"/>
    <property name="inputSource">
        <bean class="org.xml.sax.InputSource">
            <constructor-arg index="0" >
                    <bean class="java.io.FileInputStream">
                        <constructor-arg index="0" type="java.lang.String" value="${queriesFileLocation}"/>
                    </bean>
            </constructor-arg>
        </bean>
    </property>
</bean>
于 2012-08-07T07:53:28.870 に答える