liferay6.2使用CXF开发WbService接口

来源:互联网 发布:麒麟ubuntu安装 编辑:程序博客网 时间:2024/06/10 01:52

1.首先,所需要的jar包,由于liferay6.2内置spring为3.0版本,为了避免冲突,所以CXF必须使用3.0以下版本,这里我选择2.7.9:


2.在web.xml里面配置CXF的servlet:

<!-- 配置CXF的Servlet -->  
<servlet>  
<servlet-name>CXF</servlet-name>  
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>  
</servlet>  
<servlet-mapping>  
<servlet-name>CXF</servlet-name>  
<url-pattern>/CXF/*</url-pattern>  
</servlet-mapping> 

3. 在service接口和实现类加上注解@WebService,如图:


注意:默认将会发布impl实现类里面所有的public类型的方法,如果想要某个方法不被发布,可以在方法上加上注解@WebMethod(exclude=true),如图:

4.在spring配置文件中配置要发布的bean:

1.application-context.xml加上头文件:
             xmlns:jaxws="http://cxf.apache.org/jaxws"
             xmlns:jaxrs="http://cxf.apache.org/jaxrs"
             xmlns:cxf="http://cxf.apache.org/core"
   xsi:schemaLocation添加:
           http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd  
           http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd  
           http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
2.配置Bean
<!-- 要发布成webservice的bean -->  
    <jaxws:endpoint id="TestServiceImpl" address="/TestService"  
        implementor="cn.gewut.portal.service.impl.TestServiceImpl" />  

然后编译发布,至此,CXF就成功集成进liferay6.2了。在浏览器访问: