Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法从WAR应用程序中的JAR文件加载BeanIO映射_Java_Spring_Jar_War - Fatal编程技术网

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

Java 无法从WAR应用程序中的JAR文件加载BeanIO映射,java,spring,jar,war,Java,Spring,Jar,War,我有一个应用程序正在用XML配置加载其Spring上下文 上下文文件存储在jar的类路径中(在META-INF/Context目录中) 通过引入一个新bean,我想从同一存档的类路径中加载一个映射文件。 由于Tomcat在Eclipse中运行,这一切都很有吸引力,但当我将WAR文件部署到QA环境时,应用程序无法启动 让我来看看代码: public class BeanIoParser implements Parser, Iterator<Message>, Initializing

我有一个应用程序正在用XML配置加载其Spring上下文

上下文文件存储在jar的类路径中(在
META-INF/Context
目录中)

通过引入一个新bean,我想从同一存档的类路径中加载一个映射文件。 由于Tomcat在Eclipse中运行,这一切都很有吸引力,但当我将WAR文件部署到QA环境时,应用程序无法启动

让我来看看代码:

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
    }
}
我的错误变成

java.io.FileNotFoundException:ServletContext资源[/classpath*:META-INF/mappings/messages beanio.xml]无法解析为绝对文件路径-web应用程序存档未展开?
如何修复?

以不同的方式解决。我以编程方式实例化
ClasspathResource
,路径以
META-INF
开头,而不是
classpath:

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