问题描述:    因为想在原来一个系统中加入osgi功能。选了felix的osgi容器并在原系统启动时配置并调用了framework的start。既在原系统中嵌入了osgi。这时若原系统中存在log4j包,且在系统启动后导入新的bundle中也有log4j包时会爆如下错误信息:log4j:ERROR A "org.apache.log4j.xml.DOMConfigurator" object is not assignable to a "org.apache.log4j.spi.Configurator" variable.
log4j:ERROR The class "org.apache.log4j.spi.Configurator" was loaded by
log4j:ERROR [org.apache.felix.framework.BundleWiringImpl@c88440] whereas object of type
log4j:ERROR "org.apache.log4j.xml.DOMConfigurator" was loaded by [sun.misc.Launcher$AppClassLoader@19821f].
log4j:ERROR Could not instantiate configurator [org.apache.log4j.xml.DOMConfigurator].
log4j:WARN No appenders could be found for logger (testosgi2.Activator).
log4j:WARN Please initialize the log4j system properly.感觉出错的原因是因为加载的classloader不同造成的冲突,org.apache.log4j.spi.Configurator是由org.apache.felix.framework.BundleWiringImpl加载的,而org.apache.log4j.xml.DOMConfigurator是由sun.misc.Launcher$AppClassLoader(原系统)加载的。最后两个WARN则表示找不到配置文件,(原系统能打印日志,bundle中却不能)。想请问一下,像上面这种包冲突问题的ERROR该如何解决?为什么bundle中log4j会找不到对应的配置文件(包括主动设置配置文件的绝对路径也不行)且不能打印日志?osgi新手,还望赐教啊~~