1.<null/>用于处理null 值.spring会把属性的空参数当作空字符串处理.
2.bean的作用域:有singleton,prototype,request,session,global session
3.有关spring中的RMI(Remote Method Invocation),spring目前支持4种远程技术:
1).RMI.通过使用RmiProxyFactoryBean和RmiServiceExporter,spring同时支持传统的RMI和通过RMIymet
调用器实现的透明远程调用.
rmi-server.xml:
<bean id="someService"
class="onlyfun.caterpillar.SomeServiceImpl"/>
<bean id="serviceExporter"
class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="someService"/>
<property name="serviceName" value="SomeService"/>
<property name="serviceInterface"
value="onlyfun.caterpillar.ISomeService"/>
</bean>
RMIServer.java:
ApplicationContext context =
new ClassPathXmlApplicationContext("rmi-server.xml");
System.out.println("启动RMI Server..");
System.out.println("请输入exit关闭Server: ");
BufferedReader reader =
new BufferedReader(
new InputStreamReader(System.in));
while(true) {
if(reader.readLine().equals("exit")) {
break;
}
}
RmiServiceExporter rmiServiceExporter =
(RmiServiceExporter) context.getBean("serviceExporter");
rmiServiceExporter.destroy();
}
rmi-client.xml:
<bean id="someServiceProxy"
class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl"
value="rmi://localhost/SomeService"/>
<property name="serviceInterface"
value="onlyfun.caterpillar.ISomeService"/>
</bean>
RMIClient.java:
public static void main(String[] args) {
ApplicationContext context =
new ClassPathXmlApplicationContext(
"rmi-client.xml");
ISomeService service =
(ISomeService) context.getBean("someServiceProxy");
String result1 = service.doSomeService("Some request");
System.out.println(result1);
int result2 = service.doOtherService(1);
System.out.println(result2);
}
2)使用Hessian,通过HessianProxyFactoryBean和HessianServiceExporter,可以使用Caucho提供的基于
Http的轻量级二进制协议来透明地暴露服务.
Hessian是使用一个特定的servert通过Http进行通讯,与RMI不同,只有将该web放在容器中运行,client就可以访问到.
web.xml:
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/service-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>*.service</url-pattern>
</servlet-mapping>
service-config.xml:
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/some.service">serviceExporter</prop>
</props>
</property>
</bean>
<bean id="someService"
class="onlyfun.caterpillar.SomeServiceImpl"/>
<bean id="serviceExporter"
class="org.springframework.remoting.caucho.HessianServiceExporter">
<property name="service" ref="someService"/>
<property name="serviceInterface"
value="onlyfun.caterpillar.ISomeService"/>
</bean>
client调用
hessian-client.xml
3.使用HTTP调用器,使用标准java序列化机制来通过HTTP暴露业务,如果你的参数或返回值是复杂类型,并且不能通过Hessian和Burlap的序列化机制进行序列化,HTTP调用器很有优势.
实际上,spring可以使用J2SE提供的标准功能或Commons的HttpClient来实现HTTP调用.
其配置方法同Hessian.
只要将service.config.xml中org.springframework.remoting.caucho.HessianServiceExporter
改为:org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter
客户端的配置文件中:org.springframework.remoting.caucho.HessianServiceExporter
改为org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean
4.再就是web service见webSerice部分.