新建webservice接口
@WebService
// 使用@WebService标识让CXF知道使用该接口来创建WSDL
public interface HelloWorldService {
public String getName(String userName);
}
新建实现类
@WebService
//@Service
public class HelloWorldServiceImpl implements HelloWorldService {
// @Autowired
public String getName(String userName) {
return "Hello Spring!" + userName;
}
}
注入容器
ApplicationContext.xml中加入如下代码
<jaxws:endpoint
id="helloWorld"
implementor="org.app.demo.spring.service.impl.HelloWorldServiceImpl"
address="/HelloWorld" />
或者
<bean id=" helloWorldService" class=" org.app.demo.spring.service.impl.HelloWorldServiceImpl" />
<jaxws:endpoint
id="helloWorld"
implementor="#helloWorldService"
address="/HelloWorld" />
注意:XML头文件需相应添加
xmlns:jaxws="http://cxf.apache.org/jaxws
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
servlet
web.xml中加入如下代码
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
點(diǎn)擊查看更多內(nèi)容
1人點(diǎn)贊
評論
評論
共同學(xué)習(xí),寫下你的評論
評論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦