1 导入struts1.2
2导入hibernate3.1
3加入spring
4配置
在web.xml中加入监听
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
在sturts-config.xml中加入plug
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" />
</plug-in>
在spring配置文件applicationContext.xml中配置
配置数据源:
<!-- 数据源 -->
<!-- MySQL数据源 --><!--
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/sample</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>123456</value>
</property>
</bean>
--><!-- Oracle数据源 -->
<!-- <bean id="dataSource" -->
<!-- class="org.springframework.jdbc.datasource.DriverManagerDataSource">-->
<!-- <property name="driverClassName">-->
<!-- <value>oracle.jdbc.driver.Driver</value>-->
<!-- </property>-->
<!-- <property name="url">-->
<!-- <value>jdbc:oracle:@localhost:1521:OracleDB</value>-->
<!-- </property>-->
<!-- <property name="username">-->
<!-- <value>scott</value>-->
<!-- </property>-->
<!-- <property name="password">-->
<!-- <value>tiger</value>-->
<!-- </property>-->
<!-- </bean>-->
<!-- SQL Server数据源 -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</property>
<property name="url">
<value>jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=threedemo</value>
</property>
<property name="username">
<value>sa</value>
</property>
<property name="password">
<value>sa</value>
</property>
</bean>
配置Hibernate会话工厂
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<!-- 在此可以配置Hibernate会话工厂的属性 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<!-- 在此可以配置.hbm.xml映射文件 -->
<property name="mappingResources">
<list>
<value>com/lifeng/bean/User.hbm.xml</value>
</list>
</property>
<!-- 在此可以匹配*.hbm.xml映射文件 -->
<!-- <property name="mappingDirectoryLocations">-->
<!-- <list>-->
<!-- <value>classpath:com/powerise/bean</value>-->
<!-- </list>-->
<!-- </property>-->
</bean>
配置事务管理器
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
配置Hibernate模板
<bean id="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
配置DAO
<bean id="userDao"
class="com.lifeng.dao.hibernate.UserDAOImpl.UserDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
service配置
<bean id="userService"
class="com.lifeng.bussiness.impl.UserServiceImpl">
<property name="userDao">
<ref bean="userDao" />
</property>
</bean>