首页 > 其他分享 >spring集成Hessian

spring集成Hessian

时间:2023-04-23 11:00:55浏览次数:34  
标签:集成 WEB ProjectClassLoader spring javaPrj Morris SpringHessian INF Hessian


1.1.1.   编写远程接口

Ihello.java

package cn.tempus.hessian;
 
public interface IHello {
  
   public String sayHello(String name);
  
 
}

1.1.2.   编写远程接口实现类

HelloImpl.java

package cn.tempus.hessian;
 
import com.caucho.hessian.server.HessianServlet;
 
public class HelloImpl extends HessianServlet implements IHello {
 
   private static final long serialVersionUID = -6448991611447150108L;
 
   public String sayHello(String name) {
      return "Hello: "+name;
   }
 
}

1.1.3.   配置web.xml

Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID"version="3.0">
<display-name>SpringHessian</display-name>
 
<servlet>
<servlet-name>remote</servlet-name>
<!-- 使用Spring的代理Servlet -->
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>namespace</param-name>
<param-value>remoting-servlet</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
 
<servlet-mapping>
<servlet-name>remote</servlet-name>
<url-pattern>/remote/*</url-pattern>
</servlet-mapping>
</web-app>

1.1.4.   配置remoting-servlet.xml

remoting-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
 
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN""http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- 接口的具体实现类 -->
<bean id="hello" class="cn.tempus.hessian.HelloImpl" />
 
<!-- 使用Spring的HessianServie做代理 -->
<bean name="/Hello"
class="org.springframework.remoting.caucho.HessianServiceExporter">
<property name="service" ref="hello" />
<!-- Hessian服务的接口 -->
<property name="serviceInterface"value="cn.tempus.hessian.IHello" />
</bean>
</beans>

1.1.5.   编写客户端

Client.java

package cn.tempus.hessian;
 
import java.net.MalformedURLException;
 
import com.caucho.hessian.client.HessianProxyFactory;
 
public class Client {
 
         public static void main(String[] args) throws MalformedURLException {
                   // Spring Hessian代理Servelet
                   String url = "http://localhost:8080/SpringHessian/remote/Hello";
                   HessianProxyFactory factory = new HessianProxyFactory();
                   IHello api = (IHello) factory.create(IHello.class, url);
 
                   System.out.println(api.sayHello("morris"));
         }
 
}

 

1.1.6.   发布项目到jetty

控制台打印信息

Running Jetty 6.1.26
2014-12-29 17:07:47.843:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
ParentLoaderPriority enabled
Context path:/SpringHessian
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\build\classes
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\com.springsource.org.aopalliance-1.0.0.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\commons-logging-1.0.4.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\hessian-4.0.37.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\spring-aop-4.1.3.RELEASE.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\spring-aspects-4.1.3.RELEASE.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\spring-beans-4.1.3.RELEASE.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\spring-context-4.1.3.RELEASE.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\spring-context-support-4.1.3.RELEASE.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\spring-core-4.1.3.RELEASE.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\spring-expression-4.1.3.RELEASE.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\spring-instrument-4.1.3.RELEASE.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\spring-instrument-tomcat-4.1.3.RELEASE.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\spring-jdbc-4.1.3.RELEASE.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\spring-jms-4.1.3.RELEASE.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\spring-messaging-4.1.3.RELEASE.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\spring-orm-4.1.3.RELEASE.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\spring-oxm-4.1.3.RELEASE.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\spring-test-4.1.3.RELEASE.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\spring-tx-4.1.3.RELEASE.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\spring-web-4.1.3.RELEASE.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\spring-webmvc-4.1.3.RELEASE.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\spring-webmvc-portlet-4.1.3.RELEASE.jar
ProjectClassLoader: entry=D:\Morris\javaPrj\SpringHessian\WebContent\WEB-INF\lib\spring-websocket-4.1.3.RELEASE.jar
2014-12-29 17:07:47.906:INFO::jetty-6.1.26
2014-12-29 17:07:48.453:INFO:/SpringHessian:Initializing Spring FrameworkServlet 'remote'
十二月 29, 2014 5:07:48 下午org.springframework.web.servlet.FrameworkServlet initServletBean
信息: FrameworkServlet 'remote': initialization started
十二月 29, 2014 5:07:48 下午org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing WebApplicationContext for namespace 'remoting-servlet': startup date [Mon Dec 29 17:07:48 CST 2014]; root of context hierarchy
十二月 29, 2014 5:07:48 下午org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from ServletContext resource [/WEB-INF/remoting-servlet.xml]
十二月 29, 2014 5:07:49 下午org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
信息: Mapped URL path [/Hello] onto handler '/Hello'
十二月 29, 2014 5:07:49 下午org.springframework.web.servlet.FrameworkServlet initServletBean
信息: FrameworkServlet 'remote': initialization completed in 968 ms
2014-12-29 17:07:49.468:INFO::Started [email protected]:8080

1.1.7.   运行客户端

结果如下:

Hello: morris

标签:集成,WEB,ProjectClassLoader,spring,javaPrj,Morris,SpringHessian,INF,Hessian
From: https://blog.51cto.com/u_6784072/6216871

相关文章

  • spring mvc注解基本配置
    1.1. 配置web.xml<?xmlversion="1.0"encoding="UTF-8"?><web-appxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee"xsi:schemaLocation="http://java.sun.com/xm......
  • 【spring boot】 重启kafka客户端连接
    背景kafka服务端重建时,kafka客户端会连不上kafka服务端,此时需要重启客户端重连代码实现@ServicepublicclassKafkaConsumerService{privateKafkaConsumer<String,String>consumer;@AutowiredprivateKafkaPropertieskafkaProperties;//在应用......
  • Spring缓存注解的使用与源码分析
    SpringCache提供了一个对缓存使用的抽象,以及大量的实现方便开发者使用。SpringCache主要提供了如下注解:注解说明@Cacheable根据方法的请求参数对其结果进行缓存@CachePut根据方法的请求参数对其结果进行缓存,和@Cacheable不同的是,它每次都会触发真实方法的调用@CacheEvict根据一定......
  • UM2080F32 基于 ARM Cortex-M0+内核的超低功 耗、高性能的、单片集成 (G)FSK/OOK 无线
    UM2080F32基于ARMCortex-M0+内核的超低功耗、高性能的、单片集成(G)FSK/OOK无线收发机的32位SoC芯片。UM2080F32工作于200MHz~960MHz范围内,支持灵活可设的数据包格式,支持自动应答和自动重发功能,支持跳频操作,支持FEC功能,同时内部集成了完整的射频接收机、射频发射机......
  • SpringMVC启动流程源码分析
    SpringMVC向WEB容器中注入了两个对象:ContextLoaderListener:由AbstractContextLoaderInitializer注入。DispatcherServlet:由AbstractDispatcherServletInitializer注入。下面分别分析这两个对象在WEB容器启动时做了什么工作?ContextLoaderListenerContextLoaderListener实现了Servle......
  • 为spring boot定制启动banner
    直接打开这个网站 https://patorjk.com/software/taag/#p=testall&f=Larry%203D&t=Type%20Something%20 输入你想要的文字内容,点TestAll即可,我们这里选择的字体是:Larry3D,你也可以根据喜好,选择自己想要的字体 复制并保存到src/main/resources/banner.txt即可 参考资料:......
  • spring boot配置mybatis出现Invalid bound statement (not found)报错的解决办法
     背景:spring-boot-starter-parent2.5.6mybatis-spring-boot-starter2.2.0我遇到这个报错,是因为使用idea创建xml文件是没有后缀,举个例子,比如你创建的是AccountMapper.xml,结果使用idea创建的是AccountMapper,根本就没有后缀!解决办法也很简单,加上后缀就可以了,不需要做其他额外的......
  • SpringDay01-入门基础知识、Bean的配置(一)
    Spring(黑马)一、基础知识1.1传统JavaWeb的缺点传统的JavaWeb在实现某个主要的业务逻辑时需要做的事情:new一个实现类对象,然后通过对象调用某个主要的方法;开启事务、提交事务、回滚事务;在日志中记录修改数据;在日志中记录异常数据等。以上传统方法带来的问题:实现类与接......
  • 记录一次艰难的云服务器部署前后端项目springBoot+mybatis和vue(两天解决的前后端跨域
    前言大家好我是歌谣今天继续给大家带来后端java的学习最近刚学习完java的一个增删改查紧接着就是部署项目了代码准备工作前端:vue后端:springboot+mybatis数据库mysql部署后端项目打包找到maven-package-runmavenbuild云服务器上面建立文件mkdir/www/springBoot创建文件......
  • SpringSecurity过滤器之HeaderWriterFilter
    HeaderWriterFilter用于对当前的HttpServletResponse添加某些浏览器保护的响应头。HeaderWriterFilter由HeadersConfigurer配置,在执行HeadersConfigurer#configure时调用createHeaderWriterFilter创建HeaderWriterFilter,同时添加了HeaderWriter集合:privateList<HeaderWriter>ge......