呼唤远方
选了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 bylog4j:ERROR [org.apache.felix.framework.BundleWiringImpl@c88440] whereas object of typelog4j: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中却不能)。