第一步: 项目名+鼠标右键+MyEclipse....Add struts capab...(配置struts)
第二步:项目名+鼠标右键+MyEclipse....Add springcapab...(配置spring)
生成spring之后的项目结构
第三步:配置数据源window+鼠标左键+show view+DB Browser
第四步:项目名+鼠标右键+MyEclipse....Add springcapab...(配置spring)
第五步 :在WebRoot/WEB-INF/web.xml(配置)
<!-- Spring配置和监听start -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/application*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
第六步:在/Src/applicationContext.xml里面配置hibernate的事物
<!-- 配置通用的事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 配置事务通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" propagation="REQUIRED"/>
<tx:method name="find*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="query*" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="*" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 配置切面 -->
<aop:config>
<aop:pointcut expression="execution(* com.ssh.service.Impl.*.*(..))"
id="serviceMethods" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethods" />
</aop:config>
(当出现The prefix "tx" for element "tx:advice" is not bound.错误时)
把applicationContext.xml的头文件换成
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
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-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
第七步:配置struts.xml的配置文件
<package name="default" namespace="/" extends="struts-default" >
<action name="admin_*" class="adminAction" method="{1}">
<result name="AddSCCE">/index.jsp</result>
</action>
</package>
当启动服务出现下面错误时
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:431)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:424)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
导入struts2-spring-plugin-2.3.8.jar 就ok啦