仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1467|回复: 18
打印 上一主题 下一主题

[学习教程] JAVA教程之spring,ioc形式与ejb3挪用

[复制链接]
透明 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-18 11:30:37 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
关于第二点:俺问问你,如果是企业级项目的话,诸如RMI,EJB,等一些关键技术,这些难道都不需要学么?如果光是使用jsp,servlet,javabean的话。我们先看看在servlet中怎样挪用ejb3:
publicclassHelloServletextendsGenericServlet{
privateHello_hello;

publicvoidsetHello(Hellohello)
{
_hello=hello;
}


publicvoidservice(HttpServletRequestreq,HttpServletResponseres)
throwsIOException,ServletException
{
PrintWriterout=res.getWriter();

out.println(_hello.hello());
}
}
然后我们看看xml中的设置办法:
<web-app>
<servletservlet-name="hello"servlet-class="com.hongsoft.HelloServlet">
<inithello="_ejb.HelloBean.HelloBean__EJB"/>
</servlet>
</web-app>
我们看到了甚么?设置文件中把HelloBean传给了setHello作为参数,固然,HelloBean实

现了Hello接口;service中,间接挪用_hello.hello(),实践挪用的是HelloBean的

hello()办法完成.
呵呵,经由过程set办法来将必要的HelloBean传送给servlet,假如我们的需求产生了改动,

新加了Hello2Bean完成,我们只必要在设置文件中举行修正就能够了,这,就是ioc形式

中的type2.
SpringFramework接纳的也是type2的ioc形式,好比spring设置文件以下:
<beans>
<beanid=“studentType1"class=“com.hongsoft.test.StudentType1"/>
<beanid=“teacher“class=“com.hongsoft.test.Teacher">
<propertyname=“student">
<refbean=“studentType1"/>
</property>
</bean>
</beans>
那末我们在代码中就能够这么利用:
publicclassTeacher{

privateStudentstudent;

publicvoidsetStudent(Studentstudent){
this.student=student;
}
//写论文办法
publicvoidwritePaper(){
student.writePaper();
}
}
如许,假如要写IOC的论文,就找一个精晓IOC的先生写;假如要写BPEL的论文,就找一个

精晓BPEL的先生写,要修正的中央,也就是设置文件罢了.



如果你学习的是市场营销,是销售,也许参加大课堂的学习会更合适,因为你的工作能力中有个基础就是搭建自己的人脉,
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-12 12:28

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表