1.代码方式
public final class Server {
public static void main(String args[]) throws Exception {
CourseBuilderImpl implementor = new CourseBuilderImpl();
JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
svrFactory.setAddress("http://localhost:9000/CourseBuilder");
svrFactory.setServiceBean(implementor);
svrFactory.getFeatures().add(new LoggingFeature());
svrFactory.create();
}
}
限制大小
public final class Server {
public static void main(String args[]) throws Exception {
JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
...
// This will only log upto 1K or 1024 characters
svrFactory.getFeatures().add(new LoggingFeature(1024));
...
}
}
指定输出文件
public final class Server {
public static void main(String args[]) throws Exception {
JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
...
svrFactory.getFeatures().add(
new LoggingFeature("<stdout>", "file://home/myLog.txt"));
...
}
}
2.注解方式
@WebService
@Features(features = "org.apache.cxf.feature.LoggingFeature")
public class CourseBuilderImpl implements CourseBuilder {
...
3.Spring集成方式
<beans>
...
<jaxws:endpoint
id="courseBuilder"
implementor="demo.cxf.logging.CourseBuilderImpl"
address="/CourseBuilder" >
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature"/>
</jaxws:features>
</jaxws:endpoint>
</beans>
本文介绍了如何使用Apache CXF框架通过三种不同的方式配置日志记录:代码方式、注解方式和Spring集成方式。代码方式直接在启动类中设置日志记录特征;注解方式在WebService类上使用@WebService注解;Spring集成方式则是在Spring配置文件中定义。
4129

被折叠的 条评论
为什么被折叠?



