标签:集成 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