我们正在使用ApacheFelix(版本4.4.1)作为嵌入式OSGi框架。提供该框架的主要应用程序使用Log4j2(版本2.0.1)
作为日志框架。存在对log4japi和log4jcore的依赖。当然,当主应用程序启动时,也会加载和配置Log4j2。主部件中触发的所有日志消息都正确写入已配置的Appender。
现在是重点。加载的所有bundle都应该能够使用与主应用程序相同的配置和日志上下文。我试图做的是提供所有Log4j2包(来自log4j2api和log4jcore),将它们作为org放入框架配置中。奥斯基。框架系统包装。额外的
。但是,当加载包时,log4j2包不会像其他提供的包那样出现在接线包列表中,并且当包类尝试访问log4j2类时,将引发异常。
所有捆绑包都以相同的方式配置,并且具有对log4j2api和Log4j2核心的Log4j2依赖关系,并提供范围。当我查看舱单时。MF使用的Log4j2包在导入包
部分中
所以我的问题是。
为什么以这种方式导出Log4j2包不起作用?我必须如何配置我的环境,以便在捆绑包和主应用程序中使用相同的LoggingContext?
以下是我在java代码中对OSGi框架的配置部分:
Map<String, String> temp = new HashMap<String, String>();
// setting parameter that the felix cache is new initialized on each
// start of the application
temp.put(org.osgi.framework.Constants.FRAMEWORK_STORAGE_CLEAN, "onFirstInit");
// setting the packages that are provided by the main system and can
// be used by the osgi bundles
temp.put(org.osgi.framework.Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
// have to export these explicitly as the automatic export does
// not work for this internal java packages
+ "com.sun.org.apache.xerces.internal.dom,"
+ "com.sun.org.apache.xerces.internal.jaxp,"
+ "com.sun.org.apache.xerces.internal.util,"
// export the looging packages
+ "org.apache.log4j," + "org.apache.logging.log4j," + "org.apache.logging.log4j.message,"
+ "org.apache.logging.log4j.simple," + "org.apache.logging.log4j.spi,"
+ "org.apache.logging.log4j.status," + "org.apache.logging.log4j.util,"
+ "org.apache.logging.log4j.impl," + "org.apache.logging.log4j.appender,"
+ "org.apache.logging.log4j.appender.db," + "org.apache.logging.log4j.appender.db.jdbc,"
+ "org.apache.logging.log4j.appender.db.jpa," + "org.apache.logging.log4j.appender.db.jpa.converter,"
+ "org.apache.logging.log4j.appender.jms," + "org.apache.logging.log4j.appender.rewrite,"
+ "org.apache.logging.log4j.appender.rolling," + "org.apache.logging.log4j.appender.rolling.action,"
+ "org.apache.logging.log4j.appender.routing," + "org.apache.logging.log4j.async,"
+ "org.apache.logging.log4j.config," + "org.apache.logging.log4j.config.json,"
+ "org.apache.logging.log4j.config.plugins," + "org.apache.logging.log4j.config.plugins.osgi,"
+ "org.apache.logging.log4j.config.plugins.processor,"
+ "org.apache.logging.log4j.config.plugins.util," + "org.apache.logging.log4j.config.plugins.visitors,"
+ "org.apache.logging.log4j.config.status," + "org.apache.logging.log4j.config.xml,"
+ "org.apache.logging.log4j.config.yaml," + "org.apache.logging.log4j.filter,"
+ "org.apache.logging.log4j.impl," + "org.apache.logging.log4j.jackson,"
+ "org.apache.logging.log4j.jmx," + "org.apache.logging.log4j.layout,"
+ "org.apache.logging.log4j.lookup," + "org.apache.logging.log4j," + "org.apache.logging.log4j.net,"
+ "org.apache.logging.log4j.net.jms," + "org.apache.logging.log4j.net.server,"
+ "org.apache.logging.log4j.net.ssl," + "org.apache.logging.log4j.pattern,"
+ "org.apache.logging.log4j.selector," + "org.apache.logging.log4j.tools,"
+ "org.apache.logging.log4j.util," + "sun.misc," + "javax.jms," + "javax.mail,"
+ "javax.mail.internet," + "javax.mail.util," + "javax.persistence," + "javax.servlet,"
+ "com.sun.xml.internal.bind");
temp.put(FelixConstants.LOG_LEVEL_PROP, "4");
OSGI_CONFIG = Collections.unmodifiableMap(temp);
捆绑包中对log4j2 libs的依赖项定义如下:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0.1</version>
<scope>provided</scope>
</dependency>
我在OSGi(Eclipse)中有log4j工作正常。
正如@Fenris Ulth所提到的,您可以为包含log4j2的log4j核心创建一个片段。xml配置文件。对于log4j2version2.3,我发现在代码开始使用log4j记录消息之前,我必须激活log4japi包,否则就会出现这里描述的错误。我通过将其设置为低启动级别的自动启动来实现这一点。
我有log4j2在osgi工作在一个相对简单的配置。
您必须创建两个片段。
这只需要将log4japi和log4j核心jar文件放到plugins目录中(如果您使用equinox,则为p2)。我有以下链条运行良好:
共享日志(jcl-over-slf4j)-
注:slf4j版本1.7。7 log4j2版本2.1
我们找到了一个解决方案,它适用于2.0版。1.而不是在清单的导入包
部分中设置所需的log4j包。MF我们已将它们添加到DynamicImport包
定义中。之后,在需要时动态连接类,所有OSGi包都可以使用相同的LoggerContext。
问题内容: 我已经嵌入了Felix。我有一些API捆绑包和Impl。API导出接口。Impl导入该接口并在激活器中注册impl。现在我要获取C隐含的OSGi 现在,我想与它进行交互。我可以反思 但是我不能投 我猜这来自不同的ClassLoader。但是我该如何解决呢?我们如何从外部与OSGi上下文进行交互?或者我们可以将其全部放入OSGi容器中? 问题答案: 如果要嵌入OSGi,则该服务的API(
我有一个简单的java项目,叫做服务器。此外,我有一个osgi api项目,它定义了一个接口BlockProvider。接下来,我有一个osgi声明性服务项目,其中有一个实现BlockProvider的服务。 在我的java项目服务器中,我有一个嵌入式osgi框架(在我的例子中是felix)。 我创建了一个bundleactivator,它安装gogo osgi捆绑包、scr捆绑包、我的api项目
我有一个面向服务的webapp,它使用IIS 8.5和通过智能卡的客户端证书身份验证。静态服务的前端通过AJAX调用多个服务。带有证书的智能卡受PIN保护。当使用Chrome、Firefox等浏览器时,PIN提示只会出现一次,似乎会被缓存以供后续使用。 但是,我们需要将webapp嵌入Windows 10。NET桌面应用程序。webapp可以工作,但是用户需要不断地输入他们的PIN,每个服务一次,
我正在学习《行动中的Spring》第四版第5章,但是我被第一个例子困住了。 以下是我的Eclipse Luna项目结构: 如果我将此项目作为Spring Boot应用程序运行,则会引发异常: 我怎样才能解决这个问题? 所有文件的内容: 随地吐痰。爪哇: SpittrWebAppInitializer.java: 网络配置。爪哇: RootConfig。爪哇: HomeController.java
我试图在EclipseIDE中运行Equinox的区域有向图束。当我在OSGi命令提示符下使用start命令运行相关的bundle时,我收到一个错误,表示无法解析该bundle。原因:缺少约束:导入包:org.osgi.framework.hooks。捆version=“1.0.0”。为了找出框架中的现有版本,我尝试了命令p org.osgi.framework.hooks.bundle。结果显示