English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Spring远程处理(通过Burlap示例)

Houssian和Burlap均由Coucho提供。

借助于 BurlapServiceExporter BurlapProxyFactoryBean 类,我们可以实现burlap提供的远程服务。 Burlap的示例与Burlap相同,您只需将Burlap更改为Burlap。

通过Burlap进行远程处理的示例

您需要创建以下文件来创建简单的Burlap应用程序:

Calculation.java CalculationImpl.java web.xml burlap-servlet.xml client-beans.xml Client.java

1、Calculation.java

这是包含一个方法多维数据集的简单接口。

package com.w3codebox;
public interface Calculation {
int cube(int number);
}

2、CalculationImpl.java

此类提供了Calculation接口的实现。

package com.w3codebox;
public class CalculationImpl implements Calculation{
    public int cube(int number) {
        return number*number*number;
    }
}

3、web.xml

在此xml文件中,我们将DispatcherServlet定义为前端控制器。如果任何请求后跟.http扩展名,它将被转发到DispatcherServlet。

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  
    <servlet
    <servlet-name>burlap</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>burlap</servlet-name>
    <url-pattern>*.http</url-pattern>
</servlet-mapping>
</web-app>

4、burlap-servlet.xml

내에 있어야 합니다.-그것은 WEB-servlet.xml을 정의했습니다. 그것은 INF 폴더에서 생성되었습니다. 그 이름은 servletname여야 합니다. CalculationImpl BurlapServiceExporter bean을 정의했습니다.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd">
    
<bean id="calculationBean" class="com.w3codebox.CalculationImpl"></bean>
<bean name="/Calculation.http" 
class="org.springframework.remoting.caucho.BurlapServiceExporter">
    <property name="service" ref="calculationBean"></property>
    <property name="serviceInterface" value="com.w3codebox.Calculation"></property>
</bean>
</beans>

5client-beans.xml

이 xml 파일에서 우리는 BurlapProxyFactoryBean bean을 정의했습니다. 이 클래스의 두 가지 속성을 정의해야 합니다.

serviceUrl serviceInterface

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd">
    
<bean id="calculationBean" 
class="org.springframework.remoting.caucho.BurlapProxyFactoryBean">
    <property name="serviceUrl" 
         value="http://localhost:8888/burlap/Calculation.http"></property>
    <property name="serviceInterface" value="com.w3codebox.Calculation"></property>
</bean>
</beans>

이 예제에서 우리의 프로젝트 이름은 마부이며, serviceURL에서 사용되는 컨텍스트 루트로 사용됩니다.


6Client.java

이 클래스는 Calculation의 인스턴스를 가져와 다중 데이터 세트 메서드를 호출합니다.

package com.w3codebox;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Client {
 public static void main(String[] args){
  ApplicationContext context = new ClassPathXmlApplicationContext("client",-beans.xml
  Calculation calculation = (Calculation)context.getBean("calculationBean");
  System.out.println(calculation.cube(3));
 }
}

이 예제를 어떻게 실행하나요

프로젝트를 시작하고 배포합니다. 여기서는 서버가8888포트 번호에서 실행합니다. 포트 번호가 다를 경우 client을 변경하십시오.-beans.xml에서 serviceURL.

그런 다음, Client.java 파일을 컴파일하고 실행합니다.