六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 314|回复: 0

Struts2 Spring Hibernate整合关键配置

[复制链接]

升级  38.67%

90

主题

90

主题

90

主题

举人

Rank: 3Rank: 3

积分
316
 楼主| 发表于 2013-1-14 23:42:20 | 显示全部楼层 |阅读模式
1.在web.xml文件里面配置<!-- Struts2 与 Spring 整合 --><context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/classes/applicationContext*.xml</param-value></context-param><!-- 整合Struts2 --><filter><filter-name>Struts2.0</filter-name><filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class></filter><filter-mapping><filter-name>Struts2.0</filter-name><url-pattern>/*</url-pattern></filter-mapping><!-- 整合Spring与Struts2的类自动加载器 --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>2.接下来就是在Spring的applicationContext.xml文件里面配置与hibernate相关的配置即可。比如说:<bean id="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><property name="configLocation"value="classpath:hibernate.cfg.xml"></property></bean><!-- 事务处理 --><bean name="HibernateTransactionManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory"></property></bean><tx:annotation-driven transaction-manager="HibernateTransactionManager"/>当然也可以不用hibernate.cfg.xml文件的,就是在Spring里面配置就可以了。<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">      <property name="mappingResources">        <list>          <value>Widget.hbm.xml</value>        </list>      </property>      <property name="hibernateProperties">        <props>          <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>        </props>      </property>      <property name="dataSource">        <ref bean="dataSource"/>      </property>    </bean>    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">      <property name="driverClassName"><value>org.hsqldb.jdbcDriver</value></property>      <property name="url"><value>jdbc:hsqldb:mem:widgets</value></property>      <property name="username"><value>sa</value></property>      <property name="password"><value></value></property>    </bean>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表