整天我正在处理这个问题。 我有此structur一个工作区:我的项目层次结构中的弹簧依赖关系
- CMN-LIB(共同的基本算法)#爪哇
- CMN-服务器(公共服务器的基于逻辑)#爪哇
- CMN-DAO(数据库接口)# Java的
- QZ-tomcat的(Tomcat项目)#的Java
- QZ-客户端(客户端)#安卓
CMN-服务器以及使用Spring CMN-道(中测试运行没有问题)。 cmn-server-spring.xml的spring配置包含common-dao-spring.xml(其中一些Handler类需要Dao支持)。 这是CMN-服务器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发生。 在“Web Deployment Assembly”的帮助下,cmn-server和cmn-dao作为JAR包含在内。
但是...我在SpringBeanAutowiringSupport
的webapp brokes:
@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
没有共道spring.xml在我CMN-的server.jar。我已经通过Java Build Path->Project->Add->cmn-dao
将cmn-dao项目添加到cmn-server上。对于JUnit测试,该配置似乎没有问题,但对于已部署的Jar文件则没有问题。
知道任何人如何解决这个问题。
感谢您的帮助。
所以你的意思是我从cmn-server-spring.xml中删除dao-reference,并通过你的例子创建位置?你有一个教程的参考链接?命名的区别仅限于我的问题... –
请注意,META-INF通常不在类路径中。 –
@StefanBeike您的评论中的问题尚不清楚。解决你的问题,然后;不要发布“这是类似我真正的问题”的代码。我在说你使用'classpath:'告诉Spring在类路径的另一个jar中查找导入的上下文XML文件。所有其他通常的规则适用。 – chrylis