cxf 简单例子学习

来源:互联网 发布:沭阳网络问政12345 编辑:程序博客网 时间:2024/05/21 06:49
最少需要的jar:
cxf-2.3.3.jar
geronimo-annotation_1.0_spec-1.1.1.jar
geronimo-jaxws_2.2_spec-1.0.jar
geronimo-stax-api_1.0_spec-1.0.1.jar
geronimo-ws-metadata_2.0_spec-1.1.3.jar
jaxb-api-2.2.1.jar
jaxb-impl-2.2.1.1.jar
neethi-2.0.4.jar
wsdl4j-1.6.2.jar
XmlSchema-1.4.7.jar
wstx-asl-3.2.9.jar
1:在web.xml 中配置
<!-- 配置CXFService框架 -->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>若是struts配置为*.action
</servlet-mapping>
2:在spring的配置文件中导入spring-cxf.xml文件
<import resource="classpath:xml/spring-cxf.xml" />
3:配置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"
xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd


http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.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" />
<http-conf:conduit name="*.http-conduit">
<http-conf:client ConnectionTimeout="3000" ReceiveTimeout="5000"/>
</http-conf:conduit>

<jaxws:server id="userServiceCxf" serviceClass="com.platform.csfservice.UserServiceCxf" address="/userservice">
<jaxws:serviceBean>
<bean class="com.platform.csfservice.impl.UserServiceCxfImpl"/>
</jaxws:serviceBean>
</jaxws:server>
</beans>
id="userServiceCxf" 唯一性,最好为每一个外放接口的管理的bean名称
如下面的例子:
接口:
@WebService
public interface UserServiceCxf extends BaseDao<User> {
@WebMethod
public User loginUser(@WebParam(name="name") String name, @WebParam(name="password") String password);
}
实现类:
@Service("userServiceCxf")
public class UserServiceCxfImpl extends BaseDaoImpl<User> implements UserServiceCxf {

@Override
public User loginUser(String name, String password) {
List<User> user = (List<User> ) this.find("from User t where t.name = ? and t.password = ?",new Object[]{"学生","4297f44b13955235245b2497399d7a93"});
System.out.println(user);
return user.get(0);
}
}

原创粉丝点击