struts1.2+spring2.0+hibernate3.1+dwr2.0组合:
1. 页面不解析${}
servlet2.5缺省不支持jstl2.0,要在jsp中写上
<@ page isELIgnored="false" @>
2. 报事务readonly问题
要注意,所有主从表关系的表,在修改或保存时,都要先查再改。
3. 用spring输出sql
<beans>
<bean id="localSessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="hibernate.properties">
<props>
<prop key="hiberante.show_sql">true</prop>
</props>
</property>
</bean>
</beans>
4.在web.xml文件中注册,默认读取WEB-INF/下的applicationContext.xml文件
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
5.可以使用监听器,将applicationContext.xml放在src下面
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
6.在struts中注册插件,认识Spring
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml" />
</plug-in>
type="org.springframework.web.struts.DelegatingActionProxy"
7.或是使用截获RequestProcesser
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"></controller>
一、ssh组合用eclipse5.5时出现的情况
1. 导入struts1.2
2. 导入spring2.0
3. 导入hibernate3.1
4. 去掉asm2.2.3.jar包,分别从引用与web-inf/lib下删除
5. 增加commons-pool.jar包
6. 增加jstl的jar 包
二、ssh组合用eclipse6.0时的情况
1. 导入struts1.2
2. 导入spring2.0,jar包全选,保持存在
3. 导入hibernate3.1,jar包全选,保存存在
4. 去掉asm2.2.3.jar/antlr/c3p/common-collections/commons-lang/commons-logging/ehcatch/log4j包,分别从引用与web-inf/lib下删除
5. 增加jstl的jar 包
6. 增加mysql.jar包
7. 增加dwr2.0.jar包
1. spring2.0
<?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/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
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="ub" class="org.bean.UserBean" scope="singleton/prototype">
</bean>
</beans>
2. spring1.2
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="userdao" class="c2.springaop.UserDao" singleton="true" />
3. 事务
<!-- 1.2的事务-->
<bean id="proxy" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>*Biz</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>tranc</value>
</list>
</property>
</bean>
<bean id="tranc" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="tm"></property>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<我们现在采用的是事务2.0>
<!-- 2.0事务 -->
<bean id="tm"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:advice id="txadvice" transaction-manager="tm">
<tx:attributes>
<tx:method name="get*" propagation="REQUIRED" />
<tx:method name="find*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="bizs" expression="execution(* org.bbs.spring.biz.*.*(..))" />
<aop:advisor advice-ref="txadvice" pointcut-ref="bizs" />
</aop:config>
7. spring中配置显示sql
在sessionFactory中加上:
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>