All
我创建了一个 jar 文件,其中包含以下 MANIFEST.MF:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: 1.6.0_25-b06 (Sun Microsystems Inc.)
Main-Class: my.Main
Class-Path: . lib/spring-core-3.2.0.M2.jar lib/spring-beans-3.2.0.M2.jar
在其根目录中有一个名为 my.config 的文件,在我的 spring-context.xml 中引用该文件,如下所示:
<bean id="..." class="...">
<property name="resource" value="classpath:my.config" />
</bean>
如果我运行该 jar,除了加载该特定文件之外,一切看起来都很好:
Caused by: java.io.FileNotFoundException: class path resource [my.config] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/D:/work/my.jar!/my.config
at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:205)
at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:52)
at eu.stepman.server.configuration.BeanConfigurationFactoryBean.getObject(BeanConfigurationFactoryBean.java:32)
at eu.stepman.server.configuration.BeanConfigurationFactoryBean.getObject(BeanConfigurationFactoryBean.java:1)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
... 22 more
- 类从 jar 内部加载
- spring 和其他依赖项从单独的 jar 加载
- spring 上下文已加载(new ClassPathXmlApplicationContext("spring-context/applicationContext.xml"))
- my.properties 被加载到 PropertyPlaceholderConfigurer ("classpath:my.properties")
- 如果我将 .config 文件放在文件系统之外,并将资源 url 更改为“file:”,一切似乎都很好......
有小费吗?
如果您的 spring-context.xml 和 my.config 文件位于不同的 jar 中,那么您将需要使用classpath*:my.config
?
更多信息here http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#resources-classpath-wildcards
另外,请确保您正在使用resource.getInputStream()
not resource.getFile()
从 jar 文件内部加载时。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)