首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Tomcat让Spring与3层web系统协同工作

使用Tomcat让Spring与3层web系统协同工作
EN

Stack Overflow用户
提问于 2012-06-26 08:24:30
回答 1查看 538关注 0票数 0

我正在向现有的Java EE项目添加新功能,该项目涉及三个层:数据、业务和表示。使用了Spring2.5和JDK 1.4.2。

业务层(域对象项目)使用Spring管理jdbc事务,并照常注入DAO和服务。它有" Spring -config.xml“来配置Spring。它工作得很好。

表示层将使用Spring2.5、纯JSP和Tomcat 5.0。然而,我被困在设置web.xml以在项目启动时加载Spring。

web.xml如下所示:

代码语言:javascript
复制
<?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>

Tomcat 5的错误堆栈跟踪如下所示:

代码语言:javascript
复制
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项目,有什么最佳实践吗?

EN

回答 1

Stack Overflow用户

发布于 2013-05-20 16:02:58

Spring-config-xml必须在根类路径上。您没有解释这个文件的位置以及如何在Tomcat中部署您的应用程序。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11199229

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档