定义webservice接口服务端

本文详细介绍了如何使用Apache CXF框架配置和部署Web服务,包括web.xml和cxf_server_beans.xml文件的设置,以及接口类和实现类的创建。强调了servlet-name、address和implementor的一致性,并提供了常见错误及其解决方案。
web.xml配置
<servlet>
   <servlet-name>xxx</servlet-name>
   <servlet-class>
      org.apache.cxf.transport.servlet.CXFServlet
   </servlet-class>
   <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
   <servlet-name>xxx</servlet-name>
   <url-pattern>/services/*</url-pattern>
</servlet-mapping>

cxf_server_beans.xml配置

<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="MessageNotificationImpl" class="com.tydic.smpm.isag.service.impl.xxxImpl"></bean>

<jaxws:endpoint id="xxxService"
   implementor="#xxxImpl"
   address="/xxx">
   <jaxws:properties>
      <entry key="mtom-enabled" value="true"/>
   </jaxws:properties>
</jaxws:endpoint>

接口类

@WebService(targetNamespace="http://server.xxx.com")
public interface xxx {
    public void methodReceipt(@WebParam(name="param1")String xxx, @WebParam(name="param2")Xxx xxx) throws java.rmi.RemoteException;
}

实现类

@javax.jws.WebService(serviceName = "xxxImpl", targetNamespace = "http://server.xxx.com",
        endpointInterface = "cn.package.xxx")
@Service("xxxImpl")
public class xxxImpl implements xxx {
    public void methodReceipt(String param1, Xxx param2) {
        
    }
}

注意事项:

1、servlet-name和address必须相同,否则由于找不到服务会报错:

No service was found

2、刚开始在实现类上没有使用注解@Service("xxxImpl")标记为bean,导致缓存和业务service注入不进去

3、implementor和@Service("xxxImpl")里面的值必须相等,否则报错找不到bean

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值