使用的IDE为MYECLIPS 5.5
首先新建一个web service工程
然后创建基本包
如 biz-----业务逻辑包
dao------数据访问对象包
util------公共使用包
entity---实体类包
web--struts的ACTION 和FORM包
等等,根据需要搭建
接着选择项目----MYECLIPS-----ADD STRUTS支持
根据需要选择
同样步骤添加HIBERNATE和spring支持
创建ACTION和ACTIONFORM
然后修改STRUTS-CONFIG.xml文件
把ACTION-BEAN中的type修改为: type="org.springframework.web.struts.DelegatingActionProxy"
添加插件: <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="classpath:applicationContext.xml"/>
</plug-in>
注意加在XML文件中<message-resources parameter="com.crm_pro.struts.ApplicationResources" />后面,要不然会报错
修改SPRING的配置文件applicationcontext.xml文件,新建bean,将bean的name属性设置为ACTION中的映射路径
如/path,其余正常设置
将myeclipse生成的spring配置文件中的头部换成
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
另将LIB中的包asm-2.23.jar删除
添加进commons-pool.jar文件(可由网上下载)
步骤基本完成
由于SPRING依赖注入是由PLUG-IN插件管理
所以在依赖注入过程中由上而下不能断层,否则将出现注入中的底层出现NULLPOINTEREXCEPTION异常
另注意各个注入元素必须有SETTER方法
声明时初始化为NULL