0

私はSpringMVCフレームワークに不慣れで、学習しようとしているので、例外がスローされます。原因は何でしょうか?

dispatcher-servlet.xmlファイルにエラーがあるようです。

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    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">
  <annotation-driven />
  <context:component-scan base-package="kz.controller" />
  <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
  </bean>
</beans:beans>

私のコントローラークラスはアノテーション駆動型ですが、次のエラーがスローされます:

HTTPステータスServlet.init()500-サーブレットディスパッチャが例外をスローした場合

タイプ例外レポート

Servlet.init()サーブレットディスパッチャへのメッセージが例外をスローしました

説明サーバーで内部エラーが発生したため、サーバーはこの要求を実行できませんでした。

例外

javax.servlet.ServletExceptionServlet.init()サーブレットディスパッチャが例外をスローした場合 :リソース[ ]org.springframework.beans.factory.xml.XmlBeanDefinitionStoreExceptionからのXMLドキュメントの23行目が無効です。ServletContext/WEB-INF/dispatcher-servlet.xml

4

2 に答える 2

3

XMLが正しくありません。Bean名前空間の下にBean名前空間を定義しました。正しいXMLは次のようになります。

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    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">



    <annotation-driven />
    <context:component-scan base-package="kz.controller" />
    <beans:bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <beans:property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <beans:property name="prefix" value="/WEB-INF/jsp/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>
</beans:beans>

通常、Springアプリケーションでは、Beanスキーマがデフォルトであるため、Beanスキーマをデフォルトに変更してから、すべての「beans:」を削除し、他のタグに「mvc:」を追加するとさらによいでしょう。

于 2012-11-09T12:31:51.463 に答える
0

エラーメッセージを確認してください。/WEB-INF/dispatcher-servlet.xmlファイルが有効なxmlファイルではないことを示しています。IDE(eclipse、intellij、netbeansなど)を使用してファイルを開くと、ファイルが無効である理由が示されているはずです。

特にエラーは

</bean>
</beans:beans>

あなたは必要ありません</bean>

結論として、優れたIDEを使用してください。パンチカードでコーディングする必要がある60年にはもういません。コードが正しいことを願っています:)。

于 2012-11-09T12:22:34.493 に答える