接口类需要注解
可以添加输入输出拦截器
package cn.itcast.cxf.server; import org.apache.cxf.interceptor.LoggingInInterceptor; import org.apache.cxf.interceptor.LoggingOutInterceptor; import org.apache.cxf.jaxws.JaxWsServerFactoryBean; import cn.itcast.webservice.userService.UserService; import cn.itcast.webservice.userService.UserServiceImpl; /** * * 使用cxf 提供的类 JaxWsServerFactoryBean 来发布一个带接口的webservice ... * * @ 作者 [email protected] * */ public class PublishUserService { /** * @param args */ public static void main(String[] args) { //创建发布服务的 类... JaxWsServerFactoryBean bean=new JaxWsServerFactoryBean(); //设置对外的访问地址 bean.setAddress("http://192.168.9.100:7418/userService"); bean.setServiceClass(UserService.class);//设置接口类型... bean.setServiceBean(new UserServiceImpl());//设置接口的实现类... //我们可以在发布服务的时候添加消息拦截器 //拦截客户端往服务端 发送的请求的消息 bean.getInInterceptors().add(new LoggingInInterceptor()); //拦截服务端往客户端返回的消息... bean.getOutInterceptors().add(new LoggingOutInterceptor()); bean.create(); } }
package cn.itcast.webservice.userService; import javax.jws.WebService; import javax.xml.ws.BindingType; import javax.xml.ws.soap.SOAPBinding; @WebService @BindingType(value=SOAPBinding.SOAP12HTTP_BINDING) public interface UserService { public void addUser(String userId); public String getUserById(int id); }
package cn.itcast.webservice.userService; public class UserServiceImpl implements UserService { @Override public void addUser(String userId) { System.out.println("小何"); } @Override public String getUserById(int id) { return "如果认定了一件事情,那么一定要把它做到最好,加油,java!"; } }
时间: 2024-10-07 18:03:58