1、 创建webservice工程

EclipsePackage Explorer→右键→newWeb Service Project

注意,build path中的编译输出路径“Default output folder”必须是:“工程名/WebContent/WEB-INF/classes

输入相关参数,可参考图示:

 

2、 引入jar

apache-cxf-2.2.12。其中已自带有spring相关jar

3、 配置web.xml

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:applicationContext.xml</param-value>

</context-param>

 

 

<!--Spring ApplicationContext 载入 -->

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

<!-- Spring 刷新Introspector防止内存泄露 -->

<listener>

<listener-class>

org.springframework.web.util.IntrospectorCleanupListener

</listener-class>

</listener>

 

 

<!-- CXF 配置 -->

<servlet>

<servlet-name>CXFServlet</servlet-name>

<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>

</servlet>

 

<servlet-mapping>

<servlet-name>CXFServlet</servlet-name>

<url-pattern>/service/*</url-pattern>

</servlet-mapping>

4、 创建服务端接口和实现类

 

接口,注意一定要有@WebService标签

/**

 * @author: 團長

 * @date: 2013-2-4-下午12:56:24

 */

package ws;

 

import javax.jws.WebService;

 

/**

 * TODO:

 *

 * @author 團長

 * @since 2013-2-4

 */

@WebService

public interface WsInt {

 

public String qa(String q);

}

 

 

实现类:

/**

 * @author: 團長

 * @date: 2013-2-4-下午12:57:03

 */

package ws;

 

/**

 * TODO:

 * 

 * @author 團長

 * @since 2013-2-4

 */

public class WsImpl implements WsInt {

 

/**

 * TODO:

 * 

 * @author 團長

 * @since 2013-2-4

 * @param q

 * @return

 * @see ws.WsInt#qa(java.lang.String)

 * 

 */

@Override

public String qa(String q) {

return "this is my life";

}

 

}

 

5、 配置applicationContext.xml

<import resource="classpath:META-INF/cxf/cxf.xml" />

<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />

 

<bean id="qaService" class="ws.WsImpl"></bean>

 

<!-- jax-ws endpoint定义 -->

<jaxws:endpoint address="/qa"><!-- 你的webservice访问路径 -->

<jaxws:implementor ref="qaService" /><!--你要发布的service -->

</jaxws:endpoint>

 

6、 console口发布到weblogic

注意发布路径必须是:“工程名/WebContent”,即与第一步中配置的编译输出路径“Default output folder”相匹配。

 

7、 浏览器访问webservice

http://localhost:7001//TestWS/service,应出现:

 

或者:http://localhost:7001//TestWS/service/qa?wsdl,应出现(部分省略):