Spring 企业级开发应用---------httpinvoke和spring的远程服务整合的应用
<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<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<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??<property name="serviceInterface"
???value="cn.com.huawei.httpinvoker.service.IUserService" />
?</bean>
</beans>
?
?
客户端的配置信息如下
package cn.com.huawei.httpinvoker.client;
import java.util.List;
import cn.com.huawei.httpinvoker.service.IUserService;
public class HttpInvokerClient {
?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.httpinvoker.client;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class HttpInvokerTest {
?public static void main(String[] args) {
??ApplicationContext ctx = new ClassPathXmlApplicationContext(
????"applicationContext.xml");
??HttpInvokerClient hessina = (HttpInvokerClient) ctx.getBean("httpInvokerclient");
??System.out.println("rmiclient:" + hessina.getUsernames());
?}
}
客户端的client。properties的属性信息
# Properties file with server URL settings for remote access.
# Applied by PropertyPlaceholderConfigurer from "clientContext.xml".
serverName=localhost
httpPort=8080
rmiPort=1199
serverPath=SpringHttpInvoker
contextPath=remoting/UserService-httpinvoker
?
?
客户端的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??<property name="serviceUrl">
???<value>http://${serverName}:${httpPort}/${serverPath}/${contextPath}</value>
??</property>
??<property name="serviceInterface">
???<value>cn.com.huawei.httpinvoker.service.IUserService</value>
??</property>
??<!--
??Comment the following in to use Apache Commons HttpClient instead of the JDK's
??standard HttpURLConnection (as used by the default SimpleHttpInvokerRequestExecutor).
??-->
??<!--
??<property name="httpInvokerRequestExecutor">
???<bean class="org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor"/>
??</property>
???-->
?</bean>
</beans>
部署发布接口