疯狂

STANDING ON THE SHOULDERS OF GIANTS
posts - 481, comments - 486, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

spring httpinvoker 例子

Posted on 2010-01-27 16:33 疯狂 阅读(2493) 评论(0)  编辑  收藏 所属分类: spring

1,创建接口:

public interface HttpInvokerTestI {

 public TestPo getTestPo(String desp);
}


实现:

public class HttpInvokertestImpl implements HttpInvokerTestI {

 @Override
 public TestPo getTestPo(String desp) {
  // TODO Auto-generated method stub
  return new TestPo(desp);
 }

}


配置:在web info下添加remote-servlet.xml

内容:

 <bean name="httpinvokertest" class="ztest.httpinvoke.HttpInvokertestImpl"/>
     <bean name="/hit" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
        <property name="service" ref="httpinvokertest"/>
        <property name="serviceInterface" value="ztest.httpinvoke.HttpInvokerTestI"/>
     </bean>

添加spring.jar spring-webmvc.jar(配置dispacherServlet用)
web.xml 添加对context和servlet的支持:

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



<servlet>  
        <servlet-name>remote</servlet-name>  
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
             <load-on-startup>1</load-on-startup>  
    </servlet>  
    <servlet-mapping>  
       <servlet-name>remote</servlet-name>  
       <url-pattern>/remoting/*</url-pattern>   
    </servlet-mapping> 

客户端配置:

<bean id="remoteService"
    class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
       <property name="serviceUrl"
           value="http://localhost:8080/ssh/remoting/hit" />
       <property name="serviceInterface" value="com.s.httpinvoker.HttpInvokerTestI"/>

    </bean>

测试类:
public static void main(String[] args) {
  ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext-bean.xml");
  HttpInvokerTestI httpInvokerTestI = (HttpInvokerTestI) context.getBean("remoteService");
  System.out.println(httpInvokerTestI.getTestPo("dddd").getDesp());
  
 }

完成。


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


网站导航: