SSH整合方案2
【案例3】SSH整合_方案2 **
案例描述
两个知识点的演示
其一,SSH整合的第二个方案
其二,Spring+JDBC+Struts2
参考代码
31) 使用工程spring4
32) 修改ssh.xml
增加<bean name="loginAction">
<?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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql:///test"></property> <property name="username" value="root"></property> <property name="password" value="root"></property> <property name="maxActive" value="10"></property> <property name="initialSize" value="2"></property> </bean> <!--注释掉Hibernate配置的bean SessionFactory--> <!-- <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="myDataSource"></property> <property name="mappingResources"> <list> <value>tarena/mapping/User.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQL5Dialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> </props> </property> </bean> <bean id="userDao" class="tarena.dao.impl.HibernateUserDAOImpl"> <property name="sessionFactory" ref="mySessionFactory"></property> </bean> <bean id="userService" class="tarena.service.impl.UserServiceImpl"> <property name="userDao" ref="userDao"></property> </bean> --> <bean id="jdbcUserDao" class="tarena.dao.impl.JdbcUserDAOImpl"> <property name="dataSource" ref="myDataSource"></property> </bean> <bean id="userService" class="tarena.service.impl.UserServiceImpl"> <property name="userDao" ref="jdbcUserDao"></property> </bean> <bean id="loginAction" class="tarena.action.LoginAction"> <property name="userService" ref="userService"></property> </bean> <!-- 声明式事务控制 --> <!-- <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="mySessionFactory"></property> </bean> --> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="myDataSource"></property> </bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="delete*" propagation="REQUIRED"/> <tx:method name="find*" read-only="true" propagation="NOT_SUPPORTED"/> <tx:method name="*" propagation="REQUIRED"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut expression="within(tarena.service..*)" id="servicePointcut"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="servicePointcut"/> </aop:config> </beans>