web.xml配置文件(转
<context-param><!--Log4j配置 在同一容器中部署多个应用不能使用默认的webAppRootKey,必须指定唯一KEY,以免冲突-->
<param-name>webAppRootKey</param-name>
<param-value>itservice.root</param-value>
<!--在log4j.properties中设置日志路径log4j.appender.file.File=${itservice.root}/WEB-INF/itservice.log-->
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
<!--可载入多个配置文件分隔符 , ; \t \n -->
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<!--指定对Spring配置中哪个sessionFactory使用OpenSessionInView-->
<param-value>sessionFactory_itdb</param-value>
</init-param>
</filter>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Struts-config.xml
<set-property property="contextConfigLocation" value="/WEB-INF/classes/action-servlet.xml" />
<!--将spring配置中关于ACTION的配置独立到一个action-servlet.xml文件中-->
</plug-in>
<!--直接使用hibernate配置文件--> <bean id="sessionFactory_itdb" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation"> <value>classpath:hibernate_itdb.cfg.xml</value> </property> </bean> <!--使用JNDI DataSource--> <bean id="it_dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName"> <value>jdbc/itdb</value> </property> </bean> <!-- Spring配置DataSource --> <!-- *********************Hibernate*********************** --><bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>classpath:init.properties</value> </property> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${dataSource.driverClassName}"></property> <property name="url" value="${dataSource.url}"></property> <property name="username" value="${dataSource.username}"></property> <property name="password" value="${dataSource.password}"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="mappingResources"> <list> <value>com/usish/shweb/hbm/ShwebFile.hbm.xml</value> <value>com/usish/shweb/hbm/ShwebLog.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop> <prop key="hibernate.show_sql">false</prop> <prop key="hibernate.jdbc.fetch_size">50</prop> <prop key="hibernate.jdbc.batch_size">30</prop> <prop key="hibernate.cache.use_second_level_cache">true</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> <prop key="hibernate.cache.use_query_cache">true</prop> </props> </property> </bean> <!--******************TransactionManager***********************--> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref local="sessionFactory" /> </property> </bean> <bean id="baseTxProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" lazy-init="true" abstract="true"> <property name="transactionManager"> <ref bean="transactionManager" /> </property> <property name="transactionAttributes"> <props> <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="get*">PROPAGATION_REQUIRED</prop> <prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="insert*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!--AOP TX--> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="get*" propagation="NEVER"/> <tx:method name="find*" propagation="NEVER"/> <tx:method name="*" propagation="REQUIRED"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="txBusinessMethods" expression="execution(* com.ztgame.blog.business.*BusinessImpl.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="txBusinessMethods"/> </aop:config> <!--annotation TX--> <tx:annotation-driven proxy-target-class="true" transaction-manager="txManager"/> Spring编程式事物 <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate"> <property name="transactionManager"> <ref bean="TransactionManager"/> </property> </bean> <bean id="courseService" class="com.test.CourseService"> <property name="transactionTemplate"> <ref bean="transactionTemplate"/> </property> </bean> private TransactionTemplate transactionTemplate; public void enrollStudent()...{ transactionTemplate.execute(new TransactionCallback()...{ public Object doInTransaction(TransactionStatus ts)...{ try ...{ // 需要事务控制的方法代码 } catch (Exception e) ...{ ts.setRollbackOnly(); //回滚 } return null; //事务提交 } }); } } 7个事务策略:
Dirty reads non-repeatable reads phantom reads |