I. web project Integration spring
1.1 open Myeclipse, create a web project (eclipse is a dynamic web project), and use J2EE5.0.
1.2 Add the basic jar package for Srping (no transactions required)
Org. springframework. beans-3.1.1.RELEASE.jar
commons-logging.jarorg.springframework.aop-3.1.1.RELEASE.jarorg.springframework.asm-3.1.1.RELEASE.jarorg.springframework.beans-3.1.1.RELEASE.jarorg.springframework.context-3.1.1.RELEASE.jarorg.springframework.context.support-3.1.1.RELEASE.jarorg.springframework.core-3.1.1.RELEASE.jarorg.springframework.expression-3.1.1.RELEASE.jarorg.springframework.orm-3.1.1.RELEASE.jarorg.springframework.web-3.1.1.RELEASE.jar
1.3 add source folder conf under the project and add applicationContext. xml to the directory. The content is as follows:
1.4 Add a listener under the web-app node in web. xml as follows:
contextConfigLocation
classpath:applicationContext.xml
org.springframework.web.context.ContextLoaderListener
Run the project.
2. Develop webservice
Create a RegeditService class as follows:
Package zxn. ws. service; import javax. jws. webParam; import javax. jws. webService; @ WebServicepublic interface RegeditService {/*** Registration Method * @ param username * @ param password * @ return */public String regedit (@ WebParam (name = "username ") string username, @ WebParam (name = "password") String password );}Create the RegeditServiceImpl class as follows:
Package zxn. ws. service; import javax. jws. webService; @ WebService (endpointInterface = "zxn. ws. service. regeditService ", serviceName =" Regedit ", targetNamespace =" http://service.ws.zxn /") public class RegeditServiceImpl implements RegeditService {/*** Registration Method * @ param username * @ param password * @ return */public String regedit (String username, String password) {return username + ", you have successfully registered! ";}}
Note: Write the package name in targetNamespace backwards and add "/" to the end; otherwise, an error is returned.
Iii. Integrate cxf with spring
3.1 Add a jar package
cxf-2.7.8.jarneethi-3.0.2.jarxmlschema-core-2.0.3.jarwsdl4j-1.6.3.jarasm-3.3.jar
3.2 Add the following content to applicationContext. xml:
3.3 Add the following cxf configuration in web. xml:
CXFServlet
org.apache.cxf.transport.servlet.CXFServlet
1
CXFServlet
/services/*
Deploy the service to tomcat. The access address is http: // localhost: 8080/CXFWS/services (the last service is the access path configured in 3.3). If so, the service is successful:
The wsdl document is as follows:
Additional source code address: http://download.csdn.net/detail/zxnlmj/7457693