使用cxf+spring搭建WebService:
1.添加jar包。此處需要注意,不同環境下所需jar也不一定相同,先添加最基礎的jar包,然後根據錯誤提示缺什麼補什麼就可以了,這裏我就不一一說明了。
2.配置web.xml文件。
3.編寫接口類。
@WebService
public interface Studentinfo{
@WebMethod
String list(@WebParam(name="str") String str);
}
4.編寫實現類。
@WebService(endpointInterface="com.cqe.webservice.remoteinterface.Studentinfo",serviceName="studentinfo",targetNamespace="http://remoteinterface.webservice.cqe.com/")
public class UploadAttenceDataImpl implements Studentinfo{
@Override
public String list(String str) {
System.out.println(str);
return "123456";
}
}
5.配置applicationContext.xml文件。
部署到本地開啓tomcat,訪問 http://123.123.126.13:8080/demo/webservice/studentinfo?wsdl
訪問成功則發佈成功。
6.調用發佈的webservice接口。
public static void main(String[] args) {
JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
Client client = clientFactory.createClient("http://123.123.126.13:8080/demo/webservice/studentinfo?wsdl");
try {
Object[] result = client.invoke("list","lalallalalal");
System.out.println(result[0]);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("調用webservice成功!");
}