27

春が初めてで、この質問が何度も聞かれていることは知っていますが、もう一度尋ねなければなりませんでした.

適切な名前空間宣言を行ったと思いますが、まだエラーに直面し "The prefix "context" for element "context:component-scan" is not bound." います

これが私の 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"
    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/spring-context-3.0.xsd">



    <bean id="point1" class="org.sri.proj.Point">
        <property name="x" value="0" />
        <property name="y" value="0" />
    </bean>

    <bean id="point2" class="org.sri.proj.Point">
        <property name="x" value="10" />
        <property name="y" value="10" />
    </bean>

    <context:component-scan base-package="org.sri.proj"/>

</beans>
4

5 に答える 5

95

context名前空間宣言をbeansアプリケーション コンテキスト ファイルのタグ定義に追加します。

<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"
    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">  
于 2013-05-21T15:25:08.370 に答える
10

はい、追加する必要があります

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.0.xsd

したがって、次のようになります。

<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"
    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">
于 2013-05-21T15:26:23.313 に答える
3

For All time Sake は単なるコピー アンド ペーストではありません。しかし。

最初に、xml ファイルで使用したコメントを確認します。xml に次のものが含まれているとします...

  1. <context:component-scan base-package="com.spring.study" />
  2. <context:annotation-config/>
  3. <mvc:annotation-driven />

次に、コードをコピーして貼り付ける前に、ヘッダーで本当に必要なものを確認してください<beans:beans section ...

ですから、上記の構成設定を満たすこのようにして、

ファイルを変更した後は、毎回必ずクリーンアップしてビルドしてください!!

     <?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:mvc="http://www.springframework.org/schema/mvc"
    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.2.xsd http://www.springframework.org/schema/task
    http://www.springframework.org/schema/task/spring-task-3.2.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <mvc:annotation-driven />
    <context:component-scan base-package="com.spring.study" />
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

</beans>

乾杯!ディーマン!

于 2014-02-06T12:59:57.107 に答える
3

http://www.springframework.org/schema/contextそこに Context( ) 名前空間がありません:

<beans:beans xsi:schemaLocation="http://www.springframework.org/schema/mvc       http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd   
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd   
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd 


http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

このコードの最後の行を追加します。

于 2013-05-21T15:26:11.140 に答える
2

xmlns:context="http://www.springframework.org/schema/context" Bean xml に追加する必要があります。

于 2017-02-20T13:45:38.877 に答える