以下是我的目录结构
/app/infra/myjar/bin --> contains my runnable jar
/app/infra/myjar/config --> contains all external config files which I want to read from code which is inside jar.
以下是我读取外部弹簧配置文件的代码
ApplicationContext basicConfig = new ClassPathXmlApplicationContext("classpath:/spring-bean-mapping.xml");
我的清单文件有以下条目。
Class-Path:
.
../config/
我还设置了 .bashrc 中的 CLASSPATH 变量指向 /app/infra/myjar/config 文件夹
当我尝试使用运行 jar 时
java -jar myjar.jar
我收到以下异常
Loading Spring Bean Mapping file
log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring-bean-mapping.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring-bean-mapping.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.vzw.esper.alerts.consumer.EsperMessagesConsumer.main(EsperMessagesConsumer.java:47)
Caused by: java.io.FileNotFoundException: class path resource [spring-bean-mapping.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:157)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
... 13 more
Exception in thread "main" java.lang.NullPointerException
at com.vzw.esper.alerts.consumer.EsperMessagesConsumer.main(EsperMessagesConsumer.java:86)
我怎么能理解这里出了什么问题?