搭建工程spring+cxf工程。添加相应的.jar
Interface:
import javax.jws.WebService;
@WebService
public interface UserService {
public String getUserName(String name);
public String getPassWord(String password);
}
Impl:
import javax.jws.WebService;
@WebService(endpointInterface = "com.bsf.gwtservice.UserService")
public class UserServiceImpl implements UserService {
@Override
public String getPassWord(String password) {
return MD5.getMDFivePassword(password);
}
@Override
public String getUserName(String name) {
return name;
}
}
spring-cxf.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<bean id="userServiceImplCxf"
class="com.bsf.gwtservice.UserServiceImpl" />
<jaxws:endpoint id="userService" implementor="#userServiceImplCxf"
address="/userServiceCxf" />
</beans>
注意:<jaxws:endpoint id="userService" implementor="#userServiceImplCxf"
address="/userServiceCxf" />
id:指在spring配置的bean的ID.
Implementor:#+实现类的bean id.
implementorClass="类全路径"
Address:指明这个web service的相对地址
配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:xml/*.xml</param-value>
</context-param>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
部署到tomcat服务器,输入:http://localhost:9100/GwtService/userServiceCxf?wsdl
客户端:
用DOS将目录切换到cxf/bin运行wsdl2java.bat生成客户端代码
其作用上面的build.xml作用一样。
附加:wsdl2java用法:
wsdl2java -p com -d src -all aa.wsdl
-p 指定其wsdl的命名空间,也就是要生成代码的包名:
-d 指定要产生代码所在目录
-client 生成客户端测试web service的代码
-server 生成服务器启动web service的代码
-impl 生成web service的实现代码
-ant 生成build.xml文件
-all 生成所有开始端点代码:types,service proxy,,service interface, server mainline, client mainline, implementation object, and an Ant build.xml file.
配置client-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:customer="http://customerservice.example.com/"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
">
<jaxws:client id="userService"
address="http://localhost:9100/GwtService/userServiceCxf"
serviceClass="com.bsf.gwtservice.UserService">
</jaxws:client>
</beans>
测试类:
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
"test/client-applicationContext.xml");
UserService service = (UserService) context.getBean("gpsService");
System.out.println(service.getPassWord("password"));
}
分享到:
相关推荐
实现Spring整合CXF发布服务。
开发环境jdk1.7,cxf版本3.1.17。 spring整合CXF开发webService所需jar包。
Spring整合CXF例子.项目里面带有Jar包.有自己写的注释.下载即可运行.不懂的可以问我
WebService小白学习 之 Spring整合CXF,添加拦截器。 博客学习地址:https://blog.csdn.net/qq_37902949/article/details/81262826
最完整的的cxf与spring整合需要的jar文件
webserivce.、cxf整合spring,用的是spring3和cxf3。欢迎大家下载尝试
spring整合cxf全jar包 一个都不能少和一个都不能多 网上那些三个jar包的不可信
spring + cxf + mybatis整合
NULL 博文链接:https://vinceyu.iteye.com/blog/1235931
自己写的spring和cxf整合的例子,为rest风格的。里面包含全部源代码和lib包,导入myeclipse即可运行,既然要那么多的分了,肯定是好的东西。
用cxf开发的webservice 以不同的方式进行发布
cxf spring maven 实例 webservice
CXF和spring整合所需jar包
spring+cxf 完整的整合jar包,下载下来就能用,很全面
前几天在网上找了很多资料来学习webservice 发现都很难看懂 不过终于还是搞定了 现在吧自己的心得贴出来
Web Service学习-CXF与Spring整合为JavaEE应用发布WebService(三)
将下载的demo(包括serviceserverdemo及serviceclientdemo,bat文件在serviceclientdemo的src下)导入eclipse即可运行使用,编译时可能需要修改jdk版本,如果导入有错,可新建web项目,按所下载demo的结构搭建即可,...