ssh配置要点
1. web.xml
A.spring:
<!-- spring 配置 start -->
<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>
<!-- spring 配置 end -->
B.struts:
<servlet>
<servlet-name>action_tmp</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
...
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
2.struts-cfg.xml
<!-- 修改type type="com.card.action.RegistAction" -->
<action name="regist" path="/regist"
type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="success" path="/user/regist_success.jsp" />
<forward name="fail" path="/usre/regist_fail.jsp" />
</action>
3.spring.xml / applicationContext.xml
A.
<!-- 底层的dao必须注入sessionFactory -->
<bean id="userDao" class="com.card.daoImpl.UserDaoImpl">
<!-- 使用HibernateSessionFactory时的配置-->
<!-- <property name="sessionFactory" ref="sessionFactory"></property> -->
<!-- 使用HibernateDaoSupport时的配置 -->
<property name="hibernateTemplate" ref="hibernateTemplate"></property>
</bean>
B.
<!-- name必须与struts中的path相同 -->
<bean name="/regist" class="com.card.action.RegistAction">
<property name="userManager">
<ref bean="userManager" />
</property>
</bean>
---------------------------------------------
技巧:
a.由参数注入时,必须要写个无参构造函数;
b.使用hibernateDaoSupport 的 getHibernateTemplate().save()时要在spring配置文件中添加事务方面的配置;
1>xsi:schemaLocation,http..
2><!-- 配置事务 -->
<context:annotation-config />
<context:component-scan base-package="com.card" />
3><bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
<!--增加此句-->
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
</bean>
4>
<!-- 定义事务管理器(声明式的事务) -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="interceptorPointCuts"
expression="execution(* com.card.daoImpl.*.*(..))" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="interceptorPointCuts" />
</aop:config>