我正在为现有的 Java EE 项目添加新功能,该项目涉及三层:数据、业务和表示。已使用 Spring 2.5 和 JDK 1.4.2。
业务层(域对象项目)使用 Spring 来管理 jdbc 事务并照常注入 DAO 和服务。它有“Spring-config.xml”来配置 Spring。它运作良好。
表示层将使用 Spring 2.5、plain JSP 和 Tomcat 5.0。但是,我坚持设置 web.xml 以在项目启动时加载 Spring。
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>
Tomcat 5 的错误堆栈跟踪如下:
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 项目的任何最佳实践?