二、配置Spring2
添加dist下的3个spring包,因为不知道哪些包是必须的,把lib里的包都加了,去除jakarta-commons/commons-attributes-compiler.jar、j2ee/servlet-api.jar、j2ee/jsp-api.jar,然后建立配置文件,我分了三个文件:
主配置文件
dao配置文件<!--sp-->xml version="1.0" encoding="UTF-8"?> <!--CTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" </sp--> "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> ... bean> <bean id="hibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> ... bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="hibernateProperties"> <ref bean="hibernateProperties"/> property> <property name="mappingResources"> <list> <value>com/baseframe/model/AppUser.hbm.xmlvalue> <!-- </span> </li> <li class=""><span><span class="comments"> 此处增加hbm </span> </span></li> <li class="alt"><span><span class="comments"> --> list> property> bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> bean> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager" ref="transactionManager"/> <property name="transactionAttributes"> <props> <prop key="*">PROPAGATION_REQUIREDprop> <prop key="amount*">PROPAGATION_REQUIRED,readOnlyprop> <prop key="find*">PROPAGATION_REQUIRED,readOnlyprop> props> property> bean> <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="beanNames"> <value>*Servicevalue> property> <property name="interceptorNames"> <list> <value>transactionInterceptorvalue> <!-- </span> </li> <li class="alt"><span><span class="comments"> 此处增加新的Interceptor </span> </span></li> <li class=""><span><span class="comments"> --> list> property> bean> <bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor"> <property name="transactionInterceptor" ref="transactionInterceptor"/> bean> beans>
service/manager配置<!--sp-->xml version="1.0" encoding="UTF-8"?> <!--CTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" </sp--> "http://www.springframework.org/dtd/spring-beans.dtd"> <beans default-autowire="byName"> <bean id="userDao" class="com.baseframe.dao.impl.UserDaoImpl"/> beans>
<!--sp-->xml version="1.0" encoding="UTF-8"?> <!--CTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" </sp--> "http://www.springframework.org/dtd/spring-beans.dtd"> <beans default-autowire="byName"> <bean id="userService" class="com.baseframe.service.impl.UserServiceImpl"/> beans>