sts 创建webservice项目_接口测试之Eclipse下webservice项目创建 青旅半醒 2023-01-05 05:18 284阅读 0赞 本文基于Axis2框架,再eclipse环境下搭建webservice项目,以用于后期使用SoapUI进行webservice接口测试。 1、下载Axis2框架 在官网http://axis.apache.org/axis2/java/core/download.html下载web service框架Axis2,这是Apache的一个子项目,注意下载的版本,最好和jdk版本匹配,JDK1.8需要下载1.7.x版本的。 ![909610079298fab8cc916e88740ac9a7.png][] 2、在eclipse中集成Axis2框架 打开eclipse软件,选择一个工程目录:webservice,然后window->preferences->Web Services->Axis2 Preferences,在其中加载解压后的axis文件夹。 ![803868d70418b2ad1db2c2764df8fc8f.png][] 3、创建web项目,并提供对外访问的java类和方法: File->New->Project->web,选择Dynamic Web Project,点击下一步: ![211e56405105ff975e40a8103e78cded.png][] 其中NewRuntime,需要配置Tomcat,如果已经安装过,只需要在此处设置安装目录即可,如果jre是1.8\_xxx,选择tomcat7版本。 ![9048f249984d3872f0fe58c6b2f423d8.png][] 完成上面配置,直接点击Finish按钮,完成项目创建。生成的工程目录如下: ![882ae0e610ec4a8f6697cd8a2412c7f7.png][] 再在Java Resources->src下创建包:com.qf,在包下创建一个类:FirstDemo.java 其中实现如下类和方法的创建: ![ac67bc07d0148a3f399612dcc4a24856.png][] 4、选择项目的web service 鼠标右键New->Other- >Web Service->Web Service选中,点击next。 ![53075e2a889e9625dd987686dae39aad.png][] 按照下面页面进行设置,其中需要点击Browser选择刚创建的java文件,点击下一步。 ![b8c1b32476caddc31e13b371766b4e9a.png][] 选择对外开放的接口方法,点击下一步: ![9cdbef0027745754a02653d13fca00d2.png][] 点击页面的Start server,启动Tomcat服务(注意端口问题,默认是8080端口,若有占用此端口的需要关闭其再试) ![c35cedd0d927f0e45e95ca0c04e883ef.png][] 启动Tomcat服务成功后,改按钮会置灰,Eclipse控制台会显示tomcat启动日志,并处于服务状态,点击该页面的Finish完成配置。 在弹出的页面中如图设置,验证通过,则web service服务搭建成功。 ![daed05ff37cd380a14d18766910a5bcf.png][] 5、查看wsdl文件 ![ba009c598e128dff3982325e35b685db.png][] 通过xml文件打开,可以找到该服务提供的接口地址,末尾拼接wsdl :http://localhost:8080/WebSerDemo/services/FirstDemo?wsdl ![1653769dc229d7bd4cbb417d94f9cb32.png][] 复制该地址到浏览器中,可以查看xml格式的内容: ![f8eccad55878398aeef8fc9c745e9c83.png][] 在浏览器中输入:http://localhost:8080/WebSerDemo/services,点击图示按钮,也可以打开上文的wsdl文件。 ![1a68fa49a925fb16bc0e863b1b9477ac.png][] [909610079298fab8cc916e88740ac9a7.png]: /images/20221119/333c829d69b2468893fa999fe28540d8.png [803868d70418b2ad1db2c2764df8fc8f.png]: /images/20221119/9ed43e4e378a450b8052a386a3574cde.png [211e56405105ff975e40a8103e78cded.png]: https://img-blog.csdnimg.cn/img_convert/211e56405105ff975e40a8103e78cded.png [9048f249984d3872f0fe58c6b2f423d8.png]: https://img-blog.csdnimg.cn/img_convert/9048f249984d3872f0fe58c6b2f423d8.png [882ae0e610ec4a8f6697cd8a2412c7f7.png]: https://img-blog.csdnimg.cn/img_convert/882ae0e610ec4a8f6697cd8a2412c7f7.png [ac67bc07d0148a3f399612dcc4a24856.png]: https://img-blog.csdnimg.cn/img_convert/ac67bc07d0148a3f399612dcc4a24856.png [53075e2a889e9625dd987686dae39aad.png]: https://img-blog.csdnimg.cn/img_convert/53075e2a889e9625dd987686dae39aad.png [b8c1b32476caddc31e13b371766b4e9a.png]: https://img-blog.csdnimg.cn/img_convert/b8c1b32476caddc31e13b371766b4e9a.png [9cdbef0027745754a02653d13fca00d2.png]: https://img-blog.csdnimg.cn/img_convert/9cdbef0027745754a02653d13fca00d2.png [c35cedd0d927f0e45e95ca0c04e883ef.png]: https://img-blog.csdnimg.cn/img_convert/c35cedd0d927f0e45e95ca0c04e883ef.png [daed05ff37cd380a14d18766910a5bcf.png]: https://img-blog.csdnimg.cn/img_convert/daed05ff37cd380a14d18766910a5bcf.png [ba009c598e128dff3982325e35b685db.png]: https://img-blog.csdnimg.cn/img_convert/ba009c598e128dff3982325e35b685db.png [1653769dc229d7bd4cbb417d94f9cb32.png]: https://img-blog.csdnimg.cn/img_convert/1653769dc229d7bd4cbb417d94f9cb32.png [f8eccad55878398aeef8fc9c745e9c83.png]: https://img-blog.csdnimg.cn/img_convert/f8eccad55878398aeef8fc9c745e9c83.png [1a68fa49a925fb16bc0e863b1b9477ac.png]: https://img-blog.csdnimg.cn/img_convert/1a68fa49a925fb16bc0e863b1b9477ac.png
还没有评论,来说两句吧...