下午新建个maven工程,配置spring文件时,A.xml引用到了B.xml中配置的bean,不过报错,找不到bean,查找到如下网址:
http://stackoverflow.com/questions/7711750/how-to-reference-a-bean-of-another-xml-file-in-spring
解决方法有两种,可以import,可以直接添加所有的配置文件一起读取,
new ClassPathXmlApplicationContext(
new String[] { "classpath:META-INF/conf/spring/this-xml-conf.xml",
"classpath:META-INF/conf/spring/that-other-xml-conf.xml" } );
其实这里不用new String[]也行的,直接
new ClassPathXmlApplicationContext( "classpath:META-INF/conf/spring/this-xml-conf.xml",
"classpath:META-INF/conf/spring/that-other-xml-conf.xml" );
也是毫无压力滴
本文介绍了在Spring框架中如何加载多个XML配置文件的方法。一种方式是使用import标签引入另一个XML文件;另一种方式是在创建ApplicationContext时指定多个XML文件路径。
948

被折叠的 条评论
为什么被折叠?



