Java 在spring中使用apachecxf拦截器和log4j记录完整的请求和响应
我试图在spring中使用ApacheCXF和Log4j记录soap web服务的请求和响应 下面是我的项目结构 我的cxf.xml是Java 在spring中使用apachecxf拦截器和log4j记录完整的请求和响应,java,spring,web-services,cxf,interceptor,Java,Spring,Web Services,Cxf,Interceptor,我试图在spring中使用ApacheCXF和Log4j记录soap web服务的请求和响应 下面是我的项目结构 我的cxf.xml是 mybean.xml log4j.properties #根记录器选项 log4j.rootLogger=信息、文件、标准输出 #将日志消息直接发送到日志文件 log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.file=C:\\wsimport\\l
mybean.xml
log4j.properties
#根记录器选项
log4j.rootLogger=信息、文件、标准输出
#将日志消息直接发送到日志文件
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.file=C:\\wsimport\\log.txt
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.patternalyout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE}%5p%c{1}:%L-%m%n
#将日志消息直接发送到标准输出
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.patternalyout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE}%5p%c{1}:%L-%m%n
我的org.apache.cxf.Logger
org.apache.cxf.common.logging.Log4jLogger
和web.xml
上下文配置位置
/WEB-INF/beans.xml
org.springframework.web.context.ContextLoaderListener
CXF服务器
org.apache.cxf.transport.servlet.CXFServlet
2.
CXF服务器
/*
index.jsp
我已经做了以上所有的事情,但我仍然没有得到带有标题的服务请求和响应日志
我使用tomcat部署我的应用程序,使用soapui执行服务
我做错了什么
请建议
但当我执行下面的代码时,我在eclipse控制台中得到了预期的结果
JaxWsProxyFactoryBean工厂=新的JaxWsProxyFactoryBean();
setServiceClass(BookShelfService.class)//服务SEI
工厂设置地址(“http://localhost:8080/springapp/bookshelfservice");
factory.getInInterceptors().add(新的LogginInterceptor());
factory.getOutiterCeptors().add(新的LoggingOutiterCeptor());
BookShelfService客户端=(BookShelfService)工厂。创建();
BookVO reply=client.getBook(“b1”);
System.out.println(“服务器说:“+reply.getAuthor());
我确信您不需要创建自己的cxf.xml,它已经由cxf核心jar提供。所以我认为你不应该覆盖它。因为它将创建一个新的Spring总线,该总线可能无法正确配置cxf方式。删除该cxf.xml以避免冲突,只需将cxf.xml导入bean.xml中,并将cxf.xml代码放入bean.xml中。尝试使用此更新的bean.xml
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:cxf="http://cxf.apache.org/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xsi:schemaLocation="http://cxf.apache.org/core
http://cxf.apache.org/schemas/core.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor" id="loggingInInterceptor" />
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" id="logOutInterceptor" />
<cxf:bus>
<cxf:ininterceptors>
<ref bean="loggingInInterceptor" />
</cxf:ininterceptors>
<cxf:outinterceptors>
<ref bean="logOutInterceptor" />
</cxf:outinterceptors>
</cxf:bus>
<jaxws:endpoint id="bookShelfService" implementor="com.test.services.BookShelfServiceImpl" address="/bookshelfservice" />
</beans>
请注意,您使用的拦截器在CXF 3.2.0中已被弃用:。如果您担心,请使用org.apache.cxf.ext.loggininterceptor(和LoggingOut)。