简体   繁体   English

无法从WAR应用程序中的JAR文件加载BeanIO映射

[英]Unable to load BeanIO mapping from JAR file in WAR application

I have an application loading its Spring context with XML configuration. 我有一个应用程序使用XML配置加载其Spring上下文。

Context files are stored in a jar's classpath (in the META-INF/context directory). 上下文文件存储在jar的类路径中(在META-INF/context目录中)。

Introducing a new bean, I want to load a beanio mapping file from within the classpath of the same archive. 介绍一个新bean,我想从同一个存档的类路径中加载一个beanio映射文件。 With Tomcat running within Eclipse it all works as a charm, but when I deploy a WAR file to our QA environment I get the application not starting. Tomcat在Eclipse中运行它可以作为一个魅力,但当我将一个WAR文件部署到我们的QA环境时,我得到的应用程序无法启动。

Let me walk the code: 让我走一下代码:

public class BeanIoParser implements Parser, Iterator<Message>, InitializingBean
{
    private StreamFactory streamFactory;

    private Resource resourceMapping; //Injected via Context

    @Override
    public void afterPropertiesSet() throws Exception
    {
        streamFactory = StreamFactory.newInstance();
        streamFactory.load(resourceMapping.getFile()); //boom here
    }
}

And then the context 然后是背景

<bean id="messagesParser" class="it.acme.BeanIoParser" scope="prototype">
    <property name="resourceMapping" value="classpath:META-INF/mappings/messages-beanio.xml" />
</bean>

And then what? 然后什么? Uhm... I have double checked the built jar file by uncompressing the war file first. 嗯......我先通过解压缩war文件来仔细检查构建的jar文件。 It all matches. 这一切都匹配。

I can see my messages-beanio.xml file correctly. 我可以正确地看到我的messages-beanio.xml文件。

But when I start the application I get the following root cause : 但是当我启动应用程序时,我得到以下根本原因

java.io.FileNotFoundException: class path resource [META-INF/mappings/messages-beanio.xml] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%208.0/temp/11-app/WEB-INF/lib/app-3.0.0.20151105.jar!/META-INF/mappings/messages-beanio.xml java.io.FileNotFoundException:类路径资源[META-INF / mappings / messages-beanio.xml]无法解析为绝对文件路径,因为它不驻留在文件系统中:jar:file:/ C:/ Program%20Files /Apache%20Software%20Foundation/Tomcat%208.0/temp/11-app/WEB-INF/lib/app-3.0.0.20151105.jar!/META-INF/mappings/messages-beanio.xml

I have also tried another way, by using classpath* (because we already faced this problem when loading Spring context from multiple jar files) 我还尝试了另一种方法,使用classpath* (因为我们在从多个jar文件加载Spring上下文时已经遇到过这个问题)

So if my bean declaration becomes 所以如果我的bean声明变成了

<property name="resourceMapping" value="classpath*:META-INF/mappings/messages-beanio.xml" />    

My error becomes 我的错误变成了

java.io.FileNotFoundException: ServletContext resource [/classpath*:META-INF/mappings/messages-beanio.xml] cannot be resolved to absolute file path - web application archive not expanded? java.io.FileNotFoundException:ServletContext资源[/classpath*:META-INF/mappings/messages-beanio.xml]无法解析为绝对文件路径 - Web应用程序存档未扩展?

How can I fix? 我该怎么办?

Solved differently. 解决方案不同。 I programmatically instantiate the ClasspathResource with path starting with META-INF and not classpath: 我以编程方式实例化ClasspathResource ,路径以META-INF开头而不是classpath:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM