完整的applicationContext.xml內容以下:java
xml version="1.0" encoding="UTF-8"?>程序員
<beans xmlns="http://www.springframework.org/schema/beans" web
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"spring
xmlns:aop="http://www.springframework.org/schema/aop" sql
xmlns:tx="http://www.springframework.org/schema/tx" express
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd apache
http://www.springframework.org/schema/aop 服務器
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd session
http://www.springframework.org/schema/tx 架構
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.microsoft.jdbc.sqlserver.SQLServerDriver">
property>
<property name="url"
value="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test">
property>
<property name="username" value="sa">property>
<property name="password" value="sa">property>
bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
prop>
<prop key="hibernate.show_sql">trueprop>
props>
property>
<property name="mappingResources">
<list>
<value>com/zlk/pojo/Users.hbm.xmlvalue>
list>
property>
bean>
< 指定事務管理器類,將sessionFactory注入,讓該事務管理器具備打開和關閉事務的能力 >
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
bean>
< 爲事務管理器類指定匹配器,經過用name指定的匹配字符串進行對對應的方法進行打開和關閉事務 >
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<tx:method name="deploy*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
tx:attributes>
tx:advice>
< 爲事務管理器類指定進行匹配的範圍,到指定的地方經過匹配器字符串進行篩選,對應上後爲該方法打開和關閉事務 >
<aop:config proxy-target-class="true">
<aop:pointcut id="managerOperation" expression="execution(* com.zlk.dao.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="managerOperation" />
aop:config>
< //////////////////工 具 類////////////////// >
<bean id="ZlkUtil" class="com.zlk.util.ZlkUtil">bean>
< //////////////////數據層開始////////////////// >
<bean id="UsersDaoImpl" class="com.zlk.dao.impl.UsersDaoImpl">
<property name="sessionFactory" ref="sessionFactory">property>
bean>
< //////////////////數據層結束////////////////// >
< //////////////////業務層開始////////////////// >
<bean id="UserBusinessImpl" class="com.zlk.business.impl.UsersBusinessImpl">
<property name="usersDao" ref="UsersDaoImpl">property>
<property name="zlkUtil" ref="ZlkUtil">property>
bean>
< //////////////////業務層結束////////////////// >
< //////////////////控制層開始////////////////// >
<bean name="/login" class="com.zlk.struts.action.LoginAction">
<property name="usersBusiness" ref="UserBusinessImpl">property>
bean>
< //////////////////控制層結束////////////////// >
beans>
4.8. 測試
部署應用程序,啓動服務器,若是發現異常: java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V 這是因爲整合時Jar包的衝突引發的。應將"Web應用程序/WEB-INF/lib/asm-2.2.3.jar"刪除便可。
再測試,成功。