亚洲区国产区激情区无码区,国产成人mv视频在线观看,国产A毛片AAAAAA,亚洲精品国产首次亮相在线

Spring遠程處理(通過Burlap示例)

Houssian和Burlap均由Coucho提供。

借助于 BurlapServiceExporter BurlapProxyFactoryBean 類,我們可以實現(xiàn)burlap提供的遠程服務(wù)。 Burlap的示例與Burlap相同,您只需將Burlap更改為Burlap。

通過Burlap進行遠程處理的示例

您需要創(chuàng)建以下文件來創(chuàng)建簡單的Burlap應(yīng)用程序:

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

1、Calculation.java

這是包含一個方法多維數(shù)據(jù)集的簡單接口。

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

2、CalculationImpl.java

此類提供了Calculation接口的實現(xiàn)。

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

3、web.xml

在此xml文件中,我們將DispatcherServlet定義為前端控制器。如果任何請求后跟.http擴展名,它將被轉(zhuǎn)發(fā)到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-INF文件夾中創(chuàng)建。它的名稱必須是servletname-servlet.xml。它為 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.nhooo.CalculationImpl"></bean>
<bean name="/Calculation.http" 
class="org.springframework.remoting.caucho.BurlapServiceExporter">
    <property name="service" ref="calculationBean"></property>
    <property name="serviceInterface" value="com.nhooo.Calculation"></property>
</bean>
</beans>

5、client-beans.xml

在此xml文件中,我們?yōu)? 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.nhooo.Calculation"></property>
</bean>
</beans>

在此示例中,我們的項目名稱為麻布,即用作serviceURL中的上下文根。


6、Client.java

該類獲取Calculation的實例并調(diào)用多維數(shù)據(jù)集方法。

package com.nhooo;
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));
 }
}

如何運行此示例

啟動并部署項目,這里我們假設(shè)服務(wù)器在8888端口號上運行。如果端口號不同,請更改client-beans.xml中的serviceURL。

然后,編譯并運行Client.java文件。