少年阿宾

那些青春的岁月

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

/**
 *
 */
package com.abin.lee.cxf;

import javax.jws.WebService;

/**
 * @author abin
 *
 */
@WebService(targetNamespace="cxf.lee.abin.com")
public interface IUserService {
 public String getMessage(String message);
}





package com.abin.lee.cxf;

import javax.jws.WebService;

@WebService(endpointInterface="com.abin.lee.cxf.IUserService")
public class UserService implements IUserService{

 public String getMessage(String message) {
  return message+" welcome to beijing";
 }
 
}






<?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:context="http://www.springframework.org/schema/context"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:jaxws="http://cxf.apache.org/jaxws"
 xmlns:cxf="http://cxf.apache.org/core"
 xmlns:wsa="http://cxf.apache.org/ws/addressing"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-beans-3.0.xsd
 http://cxf.apache.org/core
 http://cxf.apache.org/schemas/core.xsd
 http://cxf.apache.org/jaxws
 http://cxf.apache.org/schemas/jaxws.xsd
 http://www.springframework.org/schema/aop
 http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context-3.0.xsd">
 <import resource="classpath:META-INF/cxf/cxf.xml" />
 <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
 <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
 
 <cxf:bus>
  <cxf:features>
   <!--日志拦截功能,用于监控soap内容,开发后可以删除 -->
   <cxf:logging/>
   <wsa:addressing/>
  </cxf:features>
 </cxf:bus> 

 <bean id="userService" class="com.abin.lee.cxf.UserService"></bean>
 <jaxws:endpoint id="userWebservice" implementor="#userService" address="/UserService" publish="true" />


</beans>

 





<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>
   <!--
     classpath*:com/abin/lee/spring/queue/applicationContext-springqueue.xml,
     classpath*:com/abin/lee/quartz/applicationContext-quartzCluster.xml,
     classpath*:com/abin/lee/quartz/applicationContext-quartzHeartCluster.xml,
     classpath*:com/abin/lee/quartz/applicationContext-activemq.xml
   -->
   classpath*:com/abin/lee/cxf/applicationContext-cxf.xml
  </param-value>
 </context-param>
 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
 <!--cxf服务启动servlet-->
 <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>/service/*</url-pattern>   
 </servlet-mapping> 






package com.abin.lee.spring;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 *
 * 获取spring容器,以访问容器中定义的其他bean
 *
 * @author lyltiger
 * @since MOSTsView 3.0 2009-11-16
 */
public class SpringContextUtil implements ApplicationContextAware {

 // Spring应用上下文环境
 private static ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
   "com/abin/lee/cxf/applicationContext-cxf.xml");

 /**
  * 实现ApplicationContextAware接口的回调方法,设置上下文环境
  *
  * @param applicationContext
  */
 public void setApplicationContext(ApplicationContext applicationContext) {
  SpringContextUtil.applicationContext = applicationContext;
 }

 /**
  * @return ApplicationContext
  */
 public static ApplicationContext getApplicationContext() {
  return applicationContext;
 }

 /**
  * 获取对象 这里重写了bean方法,起主要作用
  *
  * @param name
  * @return Object 一个以所给名字注册的bean的实例
  * @throws BeansException
  */
 public static Object getBean(String name) throws BeansException {
  return applicationContext.getBean(name);
 }

}









package com.abin.lee.cxf.test;

import com.abin.lee.cxf.UserService;
import com.abin.lee.spring.SpringContextUtil;

import junit.framework.TestCase;

public class TestUserService extends TestCase{
 public void testcxf(){
  UserService userService=(UserService)SpringContextUtil.getBean("userService");
  
  String response=userService.getMessage("abin");
  System.out.println("response="+response);
  System.exit(0);
 }
}


posted on 2012-08-21 00:27 abin 阅读(876) 评论(0)  编辑  收藏 所属分类: springcxf

只有注册用户登录后才能发表评论。


网站导航: