0

私は、データ、ビジネス、プレゼンテーションの3つの層を含む既存のJavaEEプロジェクトに新しい機能を追加することに取り組んでいます。Spring2.5およびJDK1.4.2が使用されています。

ビジネス層(ドメインオブジェクトプロジェクト)は、Springを使用してjdbcトランザクションを管理し、通常どおりDAOとサービスを注入します。Springを構成するための「Spring-config.xml」があります。それはうまくいきます。

プレゼンテーション層では、Spring 2.5、プレーンJSP、Tomcat5.0を使用します。ただし、プロジェクトの起動時にSpringをロードするようにweb.xmlを設定することに固執しています。

web.xmlは次のようなものです。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"        xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>TestSpring25Web</display-name>
<listener>
    <description>
  loads the spring application context on startup
</description>
    <display-name>spring application context loader listener</display-name>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:web-applicationContext.xml</param-value>
</context-param>
<context-param>
    <param-name>locatorFactorySelector</param-name>
    <param-value>
        classpath:Spring-config.xml
    </param-value>
</context-param>
<context-param>
    <param-name>parentContextKey</param-name>
    <param-value>businessBeanFactory</param-value>
</context-param>
<welcome-file-list>
    <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>
<!-- DWR -->
<servlet>
    <display-name>DWR Servlet</display-name>
    <servlet-name>dwr-invoker</servlet-name>
    <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
    <init-param>
        <param-name>debug</param-name>
        <param-value>true</param-value>
    </init-param>
</servlet>
<servlet-mapping>
    <servlet-name>dwr-invoker</servlet-name>
    <url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
</web-app>

Tomcat5のエラースタックトレースは次のようになります。

SEVERE: Context initialization failed
org.springframework.beans.factory.access.BootstrapException: Unable to initialize group     definition. Group resource name [classpath:Spring-config.xml], factory key     [businessBeanFactory]; nested exception is     org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML     document from class path resource [Spring-config.xml]; nested exception is     java.io.FileNotFoundException: class path resource [Spring-config.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:385)
at org.springframework.web.context.ContextLoader.loadParentContext(ContextLoader.java:336)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:186)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)

明らかに「Spring-config.xml」が見つからないと文句を言います。ただし、ドメインプロジェクトはWebプロジェクトの依存関係として設定されています。

私はSpringを初めて使用しますが、誰かが私にいくつかのヒントを教えてくれるでしょうか?ありがとう

このような3層Springプロジェクトの構成に関するベストプラクティスはありますか?

4

1 に答える 1

0

Spring-config-xml はルート クラスパス上にある必要があります。このファイルの場所と、アプリケーションを Tomcat にデプロイする方法については説明していません。

于 2013-05-20T08:02:58.163 に答える