【发布时间】:2013-12-25 21:38:11
【问题描述】:
我整天都在解决这个问题。 我有一个具有这种结构的工作区:
- cmn-lib(常用基本算法)#Java
- cmn-server(基于通用服务器的逻辑)#Java
- cmn-dao(数据库接口)#Java
- qz-tomcat(tomcat项目)#Java
- qz-client(客户端)#Android
cmn-server 以及 cmn-dao 使用 Spring(测试运行没有问题)。 cmn-server-spring.xml的spring配置包含common-dao-spring.xml(因为有些Handler类需要Dao支持)。 这是 cmn-server-spring.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" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:annotation-config />
<import resource="cmn-dao-spring.xml" />
<bean id="scoreHandler" class="de.bc.qz.handler.score.ScoreHandler"
autowire="byName">
</bean>
</beans>
现在我想将所有这些库包含到 qz-tomcat 中。 问题是那个异常:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [cmn-dao-spring.xml]
Offending resource: URL [jar:file:/C:/Users/BC/qz/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/quiz-tomcat/WEB-INF/lib/cmn-server.jar!/cmn-serv-spring.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from URL [jar:file:/C:/Users/BC/qz/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/quiz-tomcat/WEB-INF/lib/cmn-server.jar!/cmn-dao-spring.xml]; nested exception is java.io.FileNotFoundException: JAR entry cmn-dao-spring.xml not found in C:\Users\BC\qz\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\quiz-tomcat\WEB-INF\lib\cmn-server.jar
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)
它发生在我启动本地 tomcat 时。 cmn-server 和 cmn-dao 在“Web 部署程序集”的帮助下作为 JAR 包含在内。
但是...我的 webapp 在SpringBeanAutowiringSupport 期间崩溃了:
@WebServlet("/ScoreServlet")
public class ScoreServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Autowired
ScoreHandler mScoreHandler;
@Autowired
TransferAdapter mTransferAdapter;
ScoreCreator mScoreCreator;
public void init(ServletConfig config) throws ServletException {
super.init(config);
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this,
config.getServletContext());
}
我的 cmn-server.jar 有问题吗? 我认为主要问题是异常中的那一行:
IOException parsing XML document from URL [jar:file:/C:/Users/BC/qz/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/quiz-tomcat/WEB-INF/lib/cmn-server.jar!/cmn-dao-spring.xml
我的 cmn-server.jar 中没有 common-dao-spring.xml。我已通过Java Build Path->Project->Add->cmn-dao 将项目 cmn-dao 添加到 cmn-server
该配置似乎适用于 JUnit 测试,但不适用于已部署的 Jar-File。
知道任何人如何解决这个问题。
感谢您的每一个帮助。
【问题讨论】: