作为第一篇文章 总的来点开头
也没啥好说的 从2010年11月开始学java到现在 javase----oracle---html+js(很水)----servlet/jsp----struts----hibernate---spring 感觉学的很快乐 也很有挑战 当然 我在上班时间也在偷偷学这个(还有点感觉刺激 要躲避领导的眼睛 观察领导的动作)
入正题吧
今天早上开始了struts2----spring的整合的 hello world
一、步骤如下
1、先配置好struts2的环境 导入jar包(如果你用的是struts2.2.2.jar 千万要去找javassist-3.7.ga.jar)、配置好struts2的struts.xml和web.xml
2、用myeclipse创建spring的支持 注意选中 aop core和 web。 然后路径要改成在webinf下面。
3、导入struts2和spring关联管理的插件jar。将struts2-spring-plugin-2.2.1.1.jar导入到bin目录下。
4、修改web.xml的配置 加入spring的listener
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
---------------配置搭建完成------------
5、写有关登录的jsp 显示的jsp
6、在src目录下面 编写 action 包名如:com.xxx.action 类名:xxxAction 在这个类中保存service的接口
7、编写service类的接口 包名:com.xxx.service 类名:xxxService
8、编写service的实现类 包名:com.xxx.service.impl 类名:xxxServiceImpl
9.在spring的 applicationContext.xml中设置所需要的action和 service实现类的bean
把struts-xml中action的 class属性的值设置为applicationContext.xml中action设置的名称
<--这一步完成了由spring来转配struts的action--->
-----------------主线完成 ----------
补充:
A、spring中bean的scope有5个属性 singleton prototype request session globalsession
默认为singleton singleton适用于无状态类(即无属性 只有方法给别人调用)
B、充分使用分层思想 这个分析起来就太长了
撞见的bug.............
2.2 版本需要的 javassist-3.7.ga.jar