Web工程创建后。
1、添加hibernate支持(无需处理hibernate的配置文件)
2、添加spring支持(SessionFactory:jdbc,jdo)
3、添加的struts支持(添加springplusin插件包)
4、修改web.xml配置文件:
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> |
5、修改applicationContext.xml配置文件
<beanname="dataSource"class="org.apache.commons.dbcp.BasicDataSource"> <propertyname="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property> <propertyname="url" value="jdbc:oracle:thin:@localhost:1521/oracle10"></property> <propertyname="username" value="bankvip"></property> <propertyname="password" value="bankvip"></property> <propertyname="maxActive" value="100"></property> <propertyname="maxIdle" value="30"></property> <propertyname="maxWait" value="500"></property> <propertyname="defaultAutoCommit" value="true"></property> </bean>
<beanid="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <propertyname="dataSource"ref="dataSource"></property> <propertyname="hibernateProperties"> <props> <propkey="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop> <propkey="show_sql">true</prop> <propkey="format_sql">true</prop> </props> </property>
</bean> |
6、部署工程,测试web是否能够部署成功,且tomcat启动正常
7、利用hibernate reverse Engneering实现RàE反转
8、创建web工程的相关包,并实现业务逻辑
Springàactionàservice(serviceImpl)àuserdao(userdaoImpl)àbean(*.hbm.xml)àdb |
9、编写spring配置文件:applicationContext.xml
加orm的管理文件: <propertyname="mappingResources"> <list> <value>com/workit/bean/BranchBean.hbm.xml</value> <value>com/workit/bean/DeptBean.hbm.xml</value> <value>com/workit/bean/MenusBean.hbm.xml</value> <value>com/workit/bean/RoleBean.hbm.xml</value> <value>com/workit/bean/PowerBean.hbm.xml</value> <value>com/workit/bean/UserBean.hbm.xml</value>
</list> </property> |
配置各个依赖bean: <beanid="userdao"class="com.workit.dao.Impl.UserDaoImpl"> <propertyname="sessionFactory" ref="sessionFactory"></property> </bean>
<beanid="userservice" class="com.workit.service.Impl.UserServiceImpl"> <propertyname="userdao" ref="userdao"></property> </bean>
<beanid="useraction" class="com.workit.action.UserAction"> <propertyname="userservice" ref="userservice"></property> </bean> |
整个文件内容如下: <?xmlversion="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<beanname="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <propertyname="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property> <propertyname="url" value="jdbc:oracle:thin:@localhost:1521/oracle10"></property> <propertyname="username" value="bankvip"></property> <propertyname="password" value="bankvip"></property> <propertyname="maxActive" value="100"></property> <propertyname="maxIdle" value="30"></property> <propertyname="maxWait" value="500"></property> <propertyname="defaultAutoCommit" value="true"></property> </bean>
<beanid="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <propertyname="dataSource"ref="dataSource"></property> <propertyname="hibernateProperties"> <props> <propkey="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop> <propkey="show_sql">true</prop> <propkey="format_sql">true</prop> </props> </property> <propertyname="mappingResources"> <list> <value>com/workit/bean/BranchBean.hbm.xml</value> <value>com/workit/bean/DeptBean.hbm.xml</value> <value>com/workit/bean/MenusBean.hbm.xml</value> <value>com/workit/bean/RoleBean.hbm.xml</value> <value>com/workit/bean/PowerBean.hbm.xml</value> <value>com/workit/bean/UserBean.hbm.xml</value>
</list> </property> </bean> <beanid="userdao" class="com.workit.dao.Impl.UserDaoImpl"> <propertyname="sessionFactory" ref="sessionFactory"></property> </bean>
<beanid="userservice" class="com.workit.service.Impl.UserServiceImpl"> <propertyname="userdao" ref="userdao"></property> </bean>
<beanid="useraction" class="com.workit.action.UserAction"> <propertyname="userservice" ref="userservice"></property> </bean>
</beans> |
10、编写struts.xml配置文件
<struts> <includefile="struts-default.xml"></include> <packagename="workit" extends="struts-default"> <actionname="UserAction_*"class="useraction"method="{1}"> <resultname="loginsucc">/main.jsp</result> <resultname="failer">/index.jsp</result>
</action>
</package> </struts> 注意:class的值应该是有spring配置actionbean的id的值 |
11、部署发布。