9

追跡できないような奇妙な問題が発生しています。これを他のサーバーと問題なく動作させていますが、これを動作させることができないようです。私の問題に最も近い投稿はこの投稿でした 要素 "context:component-scan" のプレフィックス "context" はバインドされていません

他のすべては、接頭辞がxmlファイルになかったためです。ここで誰かが私を正しい方向に向けることができることを願っています。

春の XML ファイル:

<?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:dwr="http://www.directwebremoting.org/schema/spring-dwr"
  xmlns:mongo="http://www.springframework.org/schema/data/mongo"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-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/data/mongo
    http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
    http://www.directwebremoting.org/schema/spring-dwr
    http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd">

    <context:annotation-config/>

だから私はそれを持っていますが、このエラーが発生しています:

org.xml.sax.SAXParseException: The prefix "context" for element "context:annotation-config" is not bound.

どんな助けにも感謝します。他に提供できるものを教えてください。

ありがとう

4

4 に答える 4

20

beansタグ属性xmlns:contextが欠落していることに気付くまで、同じ問題が発生していました。以下の行を追加しただけです

xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
...."

次に、プロジェクトを再構築します。

それはその後うまくいきました。

于 2013-11-22T11:34:31.343 に答える
14

以下は私にとってはうまくいきます:

test.xml

<?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:dwr="http://www.directwebremoting.org/schema/spring-dwr"
  xmlns:mongo="http://www.springframework.org/schema/data/mongo"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-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/data/mongo
    http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
    http://www.directwebremoting.org/schema/spring-dwr
    http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd">

    <context:annotation-config/>

</beans>

次のクラスを使用して実行すると:

テスト.java

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Test {

    public static void main(String[] args) throws Exception {
        new ClassPathXmlApplicationContext("test.xml");
        System.out.println("Finished!");
    }

}

これがあなたに当てはまるかどうか見てもらえますか?クラスパスには次のライブラリが必要です: commons-logging、spring-asm、spring-beans、spring-context、spring-core、および spring-expression。

うまくいったかどうか教えてください。そうでない場合は、完全なスタック トレースを投稿してください。最後に、上記には Spring 3.1.1 を使用しました。

于 2013-08-09T00:17:24.590 に答える