【发布时间】:2013-06-20 16:19:18
【问题描述】:
我有一个带有 JAR 和 WAR 的 EAR,以及一个带有我的 Spring 定义的 beans.xml。我正在使用 Maven 来构建这个项目。 JAR 中的代码正在尝试查找 beans.xml,但没有找到。
我想要 beans.xml 吗:
EAR 的 META-INF/beans.xml?
或
JAR 的 META-INF/beans.xml?
我尝试了以下方法:
失败 1:JAR 的 META-INF/beans.xml
String CONFIG_FILE_NAME = "META-INF/beans.xml";
ApplicationContext context = new FileSystemXmlApplicationContext(CONFIG_FILE_NAME);
BeanFactory factory = context;
这给出了:
BeansDeployer 部署 org.apache.webbeans.exception.WebBeansException:无法读取给定输入流的根元素。 ... 原因:java.net.ConnectException:连接超时:连接
失败 2:EAR 的 META-INF/beans.xml
String CONFIG_FILE_NAME = "classpath*:/META-INF/*beans.xml";
ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG_FILE_NAME);
BeanFactory factory = context;
这会产生 FileNotFoundException,因为 maven-ear-plugin 仅复制 application.xml,但在对应用程序进行 EAR 处理时不包括 beans.xml。如果这是正确的方法,有没有办法让 Maven 在构建时包含 beans.xml?
还是应该完全在别处?
问候
【问题讨论】:
标签: java spring maven dependency-injection ear