我已经使用 CXF 3.1 wsdl2java 生成了我的服务,所以没有 cxf.xml。
我正在尝试将服务的请求和响应 XML 添加到我的 log4j2 设置中。由于版本更改等原因,存在大量冲突信息。我的请求/响应 xml CXF 日志文件始终为空。
这是最接近我的设置:How to log CXF webservice requests with log4j2?
所以我的 log4j2.xml 中有以下内容
<logger name="org.apache.cxf" additivity="false" level="info">
<AppenderRef ref="APP_LOG_FILE"/>
</logger>
<logger name="org.apache.cxf.interceptor.LoggingInInterceptor" additivity="false" level="info">
<AppenderRef ref="WS_LOG_FILE" />
</logger>
<logger name="org.apache.cxf.interceptor.LoggingOutInterceptor" additivity="false" level="info">
<AppenderRef ref="WS_LOG_FILE" />
</logger>
Run Code Online (Sandbox Code Playgroud)
没有显示附加程序,但它们在那里, APP_LOG_FILE 已填充,但 WS_LOG_FILE 附加程序文件始终为空,同时交换消息。
我添加了一个包含此内容的 META-INF/cxf/org.apache.cxf.Logger 文件
org.apache.cxf.common.logging.Slf4jLogger
Run Code Online (Sandbox Code Playgroud)
我还尝试在运行我的 jar 时使用附加命令行参数作为 cxf.Logger 文件的替代:
-Dorg.apache.cxf.Logger=org.apache.cxf.common.logging.Slf4jLogger
Run Code Online (Sandbox Code Playgroud)
我添加了额外的依赖:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我尝试了以下两种使用日志拦截器(它们是必需的还是可以替代 log4j2.xml 中的配置?)和没有它们的情况,如当前注释所示。
GetComparisonDecisionService equinitiComparisonService = new GetComparisonDecisionService();
GetComparisonDecisionInterface comparison …Run Code Online (Sandbox Code Playgroud) 我真的很努力地将 logback-classic 的加载作为传递依赖问题。我遵循了 stackoverflow 上的建议,但是,它不断重复出现。
我使用 Maven 排除来尝试控制它,它根本没有出现在我的 pom 依赖关系层次结构中。但它仍然被加载!
这是我的运行时跟踪
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/david/.m2/repository/de/ruedigermoeller/kontraktor-http/3.33/kontraktor-http-3.33.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/david/.m2/repository/ch/qos/logback/logback-classic/1.2.1/logback-classic-1.2.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
W 13:22:24:837 : DispatcherThread 1 : DispatcherThread :
java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getLoggerFactoryClassStr()Ljava/lang/String;
at org.slf4j.LoggerFactory.reportActualBinding(LoggerFactory.java:271)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:143)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:120)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:331)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:283)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:304)
at org.quartz.impl.StdSchedulerFactory.<init>(StdSchedulerFactory.java:284)
at org.quartz.impl.StdSchedulerFactory.getDefaultScheduler(StdSchedulerFactory.java:1539)
at uk.co.example.ExampleEwsService.init(ExampleEwsService.java:296)
Run Code Online (Sandbox Code Playgroud)
部分问题在于 Kontraktor 框架重写了 StaticLoggerBinder.getLoggerFactoryClassStr 方法。但很容易确保它首先被加载,然后从正在加载它的quartz中排除logback-classic,如下所示:
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.3</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId> …Run Code Online (Sandbox Code Playgroud)