首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

打成jar包找不到spring配置文件?解决方法

2013-08-01 
打成jar包找不到spring配置文件?maven项目,eclipse export runnable jar之后,运行jar java -jar xxx.jar

打成jar包找不到spring配置文件?
maven项目,eclipse export runnable jar之后,
运行jar java -jar xxx.jar 找不到jar包中的spring配置文件
下面是项目结构:
打成jar包找不到spring配置文件?解决方法
我可以确定打成的jar文件没问题,applicationContext在根目录下

启动的main方法:


public static void main(String[] args) {
ApplicationContext context =new ClassPathXmlApplicationContext(new String[]    {"applicationContext.xml","task.xml"});
}

运行后报错:

hy
[2013-07-24 09:55:23,864   INFO at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:315)] Loading XML bean definitions from class path resource [applicationContext.xml]
Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]
Offending resource: class path resource [applicationContext.xml]


求一个解决办法,怎么才能找到这个配置文件呢,扯蛋的就别回答了. Spring JAR Java
[解决办法]
你好,我也发现了这个问题,去网上查了一下,试了,如果你是工程直接调用该jar包(classPath相同)的话,用下面的:
ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:config/appContext.xml");
即加载处于classpath下的文件,但是这个加载不直观,因为即使找不到文件,spring也不会报错,只是返回的applicationContext没有内容,这种可以直接读取到

热点排行