springMVC 基于jws的webservice建立
在已有的springmvc+spring+mybatis框架的基础上,基于jws创建webservice很简单,跟平常写接口一样,只是多个@WebService的注解。
示例如下:
1、接口
@WebService(serviceName="example")
public interface IWsExample{
@WebMethod
public String getInfo(String id);
}
2、实现类:
@Service
@WebService(endpointInterface="com.test.IWsExample")---对应上面接口
public class wsExampleImpl implements IWsExample{
@Override
public String getInfo(String id){
System.out.println("webservice测试");
}
}
增加配置文件spring-context-jaxws.xml
3、生成客户端代码
使用jdk自带的wsimport工具生成。
wsimport -d d: -keep -p "com.test" http://192.168.1.10:8088/example?wsdl
生成的客户端代码在d:盘com/test下
4、写个测试类,调用webService方法
public void main(String[] args){
ExampleImplService server=new ExampleImplService ();
IExample serverImpl=server.getExampleImplPort();
System.out.println(serverImpl.getInfo("lalala"));
}