struts1.x hibernate spring框架的整合
在applicationContext.xml文件中的配置如下
<beans>
<!--DataSource-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value>
</property>
<property name="url">
<value>jdbc:sqlserver://localhost:1433;DatabaseName=你的数据库名称;Select Method="cursor"</value>
</property>
<property name="username">
<value>sa</value>
</property>
<property name="password" >
<value>pwd<value>
</property>
</bean>
<!--sessionFactory-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource"/>
</property>
<property name="mappingResources">
<list>
<value>实体类的映射文件</value>
<value>--------------</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="hibernate.show_sql">
true
</prop>
</props>
</property>
</bean>
<!-dao-->
<bean id="userDao" class="com.daoImpl.userDaoImpl">
<property name="sessionFactory" ref="sessionFactory">
</bean>
<!--biz-->
<bean id="userBiz" class="com.bizImpl.userBizImpl">
<property name="userDao" ref="userDao">
</property>
</bean>
<!-- action -->
<bean name="/user" class="com.action.UserAction">
<property name="userBiz" ref="userBiz">
</property>
</bean>
</beans>
为了让spring生成action的实例,应该在struts-config.xml文件中配置插件,在struts-config.xm中的配置是
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation">
<value>classpath:applicationContext.xml</value>
</set-property>
</plug-in>
还有就是将相应的<action name="" type="">中的type改成 type="org.springframework.web.struts.DelegatingProxyAction>
struts1.x hibernate spring集成的第二种方式
1.在web.xml中配置监听器,就不用在struts-config.xml中配置 plugIn插件
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<Context>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
</param-value>
</Context>
2.完成Action,由spring管理struts-config.xml,在struts-config.xml文件中配置controller
<Controller>
<set-property property="processor" value="org.springframework.web.struts.DelegatingRequestProcessor">
</Controller>
这个配置要放在<message-resource>之前
3.在spring 中配置Action