使用嵌入式Jetty和Tapestry进行日志记录

用户名

我有一个正在使用Tapestry框架的战争Web应用程序。它使用slf4j + log4j并运行良好。

我还有一个带有嵌入式码头8的简单服务器应用程序,用于部署战争。

我也想在服务器中使用slf4j + log4j。

因此,我将slf4j和log4j依赖项添加到服务器pom.xml中:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.5</version>
</dependency>

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.5</version>
</dependency>

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>

我得到:

SLF4J: Class path contains multiple SLF4J bindings.<br/>
SLF4J: Found binding in [jar:file:/tmp/jetty-0.0.0.0-8080-web-app-0.0.1.war-_-any-/webapp WEB-INF/lib/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/martin/monitoring-gui/trunk/release/target/release-0.0.1-webgui-distribution/release-0.0.1/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]

公平地说,Tapestry依赖关系自动包含slf4j-log4j12log4j因此,我将以下内容添加到我的webapp pom.xmltapestry-core部分:

<exclusions>  
    <exclusion>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
    </exclusion>

    <exclusion>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
    </exclusion>
</exclusions>

现在,实际的绑定和记录器仅应存在于服务器应用程序中。但是在服务器启动时,我得到:

Exception in thread "main" java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/eclipse/jetty/webapp/WebAppClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of sun/misc/Launcher$AppClassLoader) for resolved class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type taticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory; used in the signature
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:299)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:269)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:281)
at org.apache.tapestry5.TapestryFilter.<init>(TapestryFilter.java:56)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.Class.newInstance(Class.java:374)
at org.eclipse.jetty.servlet.ServletContextHandler$Context.createFilter(ServletContextHandler.java:1051)
at org.eclipse.jetty.servlet.FilterHolder.doStart(FilterHolder.java:104)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:763)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:265)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1242)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
at org.eclipse.jetty.server.Server.doStart(Server.java:282)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
...

一直到我的码头Server.start()调用;

我想念什么?

用户名

好的,谢谢您的帮助joostschouten和user2424794。我已经工作了。

mvn dependency:tree透露,其他Web应用程序的依赖:qpid-client导入到另一slf4j-api战争。
因此,另一个排除是必要的:

<dependency>
    <groupId>org.apache.qpid</groupId>
    <artifactId>qpid-client</artifactId>
    <version>0.22</version>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </exclusion>
    </exclusions>
</dependency>

作为记录,tapestry-core依赖项:

<dependency>
    <groupId>org.apache.tapestry</groupId>
    <artifactId>tapestry-core</artifactId>
    <version>${tapestry-release-version}</version>
    <exclusions>  
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </exclusion>
        <exclusion>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
        </exclusion>
    </exclusions>
</dependency>

剩下的唯一问题是,如果没有slf4j-api,战争将无法编译,因此我将其添加为战争的编译依赖项,而不是链接的依赖项-maven的provided范围:

<dependency>
     <groupId>org.slf4j</groupId>
     <artifactId>slf4j-api</artifactId>
     <version>1.7.5</version>
     <scope>provided</scope>
</dependency>

当然slf4j-apislf4j-log4j12log4j会作为服务器的依赖项添加,从而将其“提供”给war应用程序。

现在一切都可以编译,运行和记录了。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

嵌入式Jetty 9日志记录和Logback

嵌入式Tomcat的log4j的使用进行日志记录

使用嵌入式Jetty和jersey建立Web应用程序,并进行请求分派

嵌入式Jetty和正常关机

Spring Boot Jetty / tomcat嵌入式访问日志配置

嵌入式码头战争部署日志以进行日志备份

使用application.yml在Spring Boot中配置嵌入式Tomcat的日志记录

如何使用嵌入式Jetty设置静态资源和自定义服务?

如何将hawt.io与Spring Boot和嵌入式Jetty结合使用

带有Jersey和嵌入式Jetty的CrossOriginFilter

Spring 3.1 WebApplicationInitializer和嵌入式Jetty 8 AnnotationConfiguration

使用SpringMVC +嵌入式Jetty + Gradle设置JSP

使用嵌入式Jetty测试Spring-Rest服务

使用嵌入式Jetty提供静态文件

使用嵌入式 Jetty 计算每秒请求数

如何在OrientDb中添加嵌入式地图以使用sql进行记录

使用Jetty嵌入式容器时,ServletContextHandler.setResourceBase和ResourceHandler.setResourceBase有什么区别?

嵌入式Jetty服务器

Jetty BadMessage嵌入式WebSocket Servlet

使用GNU make,嵌入式C进行本机和交叉编译

如何注释/记录Pylint嵌入式选项的使用?

SpringBoot 2.1.3:嵌入式Tomcat的日志

Spring Boot嵌入式tomcat日志

如何查看嵌入式python解释器中的日志记录输出?

如何在Spring Boot中设置嵌入式tomcat的日志记录级别?

嵌入式(路由器)Linux上最少的CPU密集型串行日志记录

intellij和嵌入式Jetty-创建名称为bean的错误

带有Appache CXF和嵌入式Jetty的Websocket上的SOAP

在嵌入式Jetty中设置默认字符编码和内容类型