CXF method
The following is the specific structure of the project
First put the jar package under lib
Then go to configure web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>CXFWebservice</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Character Encoding filter -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<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>/webservice/*</url-pattern>
</servlet-mapping>
</web-app>
classpath:/applicationContext.xml is the path to the spring configuration file /webservice/* is the address content of wsdl Write interfaces and implementation classes, pay attention to writing annotations
//接口类
@WebService
public interface SendService {
public boolean sendOA(@WebParam(name="param")String param);
}
//接口的实现类
@WebService(endpointInterface="com.siyuan.SendService",serviceName="sendService")
public class SendServiceImpl implements SendService{
@Override
public boolean sendOA(String param) {
System.out.println("-------sendOA---------param:"+param);
if(param.equals("alice")){
return true;
}
return false;
}
}
file to configure spring
<?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:p="http://www.springframework.org/schema/p"
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://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<jaxws:endpoint id="sendServie" implementor="com.siyuan.SendServiceImpl"
address="/sendServie" />
<!-- <jaxws:client id="sendServiceClient" serviceClass="com.service.SendService"
address="http://10.137.138.11:9080/Wb/webservice/sendServie?wsdl" />-->
</beans>
The "jaxws:client" tag does not need to be written, and the url can be manually spliced when accessing Publish to tomcat to start in eclipse
Indicates that the service was published successfully, visit the project http://localhost:8080/CXFWebservice/webservice
You can see that the project has two services, click the wsdl connection to see the information below
Of course, you can also put this project into a war package and put it on a remote server
Then start tomcat to access the ip+tomcat port number of the remote server
Client calling method of CXF webservice
public static void main(String[] args) throws Exception, IllegalAccessException, InvocationTargetException {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://localhost:8080/CXFWebservice/webservice/sendServie?wsdl");
client.invoke("sendOA", "aa");
}
{{o.name}}
{{m.name}}