我们先看看ejb3的slsb的实现:
import javax.ejb.stateless;
@stateless
public class hellobean{
private string _greeting = "default hello";
public void setgreeting(string greeting)
{
_greeting = greeting;
}
public string hello()
{
return _greeting;
}
}
然后我们看看xml中的配置方法:
<ejb-server>
<bean type="...">
<init greeting="hello, world"/>
</bean>
</ejb-server>
我们看到了什么?配置文件中把"hello, world"传给了setgreeting作为参数,当然,ejb实现根据默认值生成了hello接口;接口的方法实现中,直接调用return _greeting;,实际返回的是"hello, world".
通过set方法来将需要的string传递给setgreeting,如果我们的需求发生了改变,我们只需要在配置文件中进行修改可以了,这,就是ioc模式中的
type2.
可见,ejb3采用的ioc模式和spring采用的ioc一样,都采用了type2方式,学了spring,对我们以后学习ejb3也是很好的铺垫.
闽公网安备 35060202000074号