一、web project整合spring

1.1、打开Myeclipse,建立web project(eclipse为dynamic web project),使用J2EE5.0。

1.2、加入Srping的基本jar包(无需事务等)

org.springframework.beans-3.1.1.RELEASE.jar

commons-logging.jar
org.springframework.aop-3.1.1.RELEASE.jar
org.springframework.asm-3.1.1.RELEASE.jar
org.springframework.beans-3.1.1.RELEASE.jar
org.springframework.context-3.1.1.RELEASE.jar
org.springframework.context.support-3.1.1.RELEASE.jar
org.springframework.core-3.1.1.RELEASE.jar
org.springframework.expression-3.1.1.RELEASE.jar
org.springframework.orm-3.1.1.RELEASE.jar
org.springframework.web-3.1.1.RELEASE.jar
javassist-3.11.0.GA.jar

1.3、新建源文件夹(source folder)conf,位于项目下,加入applicationContext.xml到该文件夹,内容例如以下:


1.4、在web.xml中web-app节点下加入监听,例如以下:

	<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>

执行项目,正常执行则说明正常。

二、开发webservice服务

新建RegeditService类,例如以下:

package zxn.ws.service;

import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public interface RegeditService {
	/**
	 * 注冊方法
	 * @param username
	 * @param password
	 * @return
	 */
	public String regedit(@WebParam(name = "username")String username, @WebParam(name="password")String password);
}
新建RegeditServiceImpl类,例如以下:
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 {
	/**
	 * 注冊方法
	 * @param username
	 * @param password
	 * @return
	 */
	public String regedit(String username, String password) {
		return username+",你已成功注冊!";
	}
}

注意:targetNamespace中的包名倒着写,最后要加"/",否则报错。

三、spring整合cxf

3.1、加入jar包

cxf-2.7.8.jar
neethi-3.0.2.jar
xmlschema-core-2.0.3.jar
wsdl4j-1.6.3.jar
asm-3.3.jar
3.2、applicationContext.xml中加入例如以下内容:

3.3、在web.xml中加入例如以下cxf配置:

    <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>/services/*</url-pattern>
     </servlet-mapping>

部署到tomcat,訪问地址:http://localhost:8080/CXFWS/services(最后的services是3.3中配置的訪问路径),例如以下图则表示成功:

使用CXF+spring创建一个web的接口项目

wsdl文档例如以下图:使用CXF+spring创建一个web的接口项目


另附上源码地址:http://download.csdn.net/detail/zxnlmj/7457693

相关文章:

  • 2021-12-21
  • 2021-12-04
  • 2021-09-30
  • 2022-12-23
  • 2021-05-17
  • 2021-07-13
  • 2021-08-06
  • 2021-12-28
猜你喜欢
  • 2022-12-23
  • 2022-01-19
  • 2021-10-06
  • 2021-11-08
  • 2021-06-12
  • 2022-02-02
相关资源
相似解决方案