- 博客分类:
- Spring 开发应用
使用burlap和spring整合发布远程服务
开发步骤
1服务端接口和实现的开发
2服务端的web.xml的配置信息
3服务端的spring和burlap的配置信息
4 部署发布服务端服务
5 客户端的配置信息
6客户端的访问信息
服务端接口和实现类
服务端的服务定义类
package cn.com.huawei.burlap.service;
import java.util.List;
public interface IUserService {
public List getUsernames();
}
服务端的服务实现类
package cn.com.huawei.burlap.service.impl;
import java.util.ArrayList;
import java.util.List;
import cn.com.huawei.burlap.service.IUserService;
public class UserService implements IUserService{
public List getUsernames()
{
List<String> usernames=new ArrayList<String>();
usernames.add("xiaobai");
usernames.add("xiaoli");
return usernames;
}
}
服务的端配置:
web。xml的配置
<?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">
<!--spring的配置文件的信息-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!---使用上下文的加载spring-->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!---使用spring的分发器将服务分发到Burlap的响应的控制类-->
<servlet>
<servlet-name>remoting</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>remoting</servlet-name>
<url-pattern>/remoting/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
注意使用spring的分发器时必须使用响应的配置信息的 servlet-name-servlet.xml配置文件:如remoting-servlet.xml
信息如下:
<?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-2.0.xsd">
<!---远程服务的burlap的在spring中配置信息-->
<bean name="/Userservice-burlap" class="org.springframework.remoting.caucho.BurlapServiceExporter">
<property name="service">
<ref bean="userservicetarget"/>
</property>
<property name="serviceInterface">
<value>cn.com.huawei.burlap.service.IUserService</value>
</property>
</bean>
</beans>
applicationContext。xml的配置信息如下:
<?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-2.0.xsd">
<!--服务实现类的--->
<bean id="userservicetarget" class="cn.com.huawei.burlap.service.impl.UserService"/>
</beans>
spring和burlap的配置文件
spring和burlap的客户端使用远程服务的服务
package cn.com.huawei.burlap.client;
import java.util.List;
import cn.com.huawei.burlap.service.IUserService;
public class BurlapClient {
private IUserService userservice;
public IUserService getUserservice() {
return userservice;
}
public void setUserservice(IUserService userservice) {
this.userservice = userservice;
}
public List getUsernames() {
return this.userservice.getUsernames();
}
}
package cn.com.huawei.burlap.client;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class BurlapTest {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext(
"applicationContext.xml");
BurlapClient hessina = (BurlapClient) ctx.getBean("burlapclient");
System.out.println("burlapclient:" + hessina.getUsernames());
}
}
client.properties 属性配置文件
# Properties file with server URL settings for remote access.
# Applied by PropertyPlaceholderConfigurer from "clientContext.xml".
serverName=localhost
httpPort=8080
rmiPort=1099
serverPath=SpringBurlap
contextPath=remoting/Userservice-burlap
客户端spring配置
<?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-2.0.xsd">
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>client.properties</value>
</property>
</bean>
<bean id="burlapclient"
class="cn.com.huawei.burlap.client.BurlapClient">
<property name="userservice">
<ref local="proxyuserservice" />
</property>
</bean>
<bean id="proxyuserservice"
class="org.springframework.remoting.caucho.BurlapProxyFactoryBean">
<property name="serviceUrl">
<value>
http://${serverName}:${httpPort}/${serverPath}/${contextPath}
</value>
</property>
<property name="serviceInterface">
<value>cn.com.huawei.burlap.service.IUserService</value>
</property>
</bean>
</beans>