当前位置: 代码迷 >> Java Web开发 >> 求大神给小弟我贴一段spring3.2+hibernate+struts2的配置到吗
  详细解决方案

求大神给小弟我贴一段spring3.2+hibernate+struts2的配置到吗

热度:772   发布时间:2016-04-16 21:46:44.0
求大神给我贴一段spring3.2+hibernate+struts2的配置到吗
本人刚刚学的ssh框架,急求大神帮忙!!在这谢谢了!
------解决思路----------------------
hibernate.cfg.xml

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>

    <session-factory>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property><!--数据库所用的方言  -->
        <property name="connection.url">jdbc:mysql://localhost:3306/ss2h?characterEncoding=UTF-8</property><!-- 配置数据库及所用到的库,和格式-->
        <property name="connection.username">root</property><!--数据库的用户名称  -->
        <property name="connection.password">123</property><!-- 数据库的密码 -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property><!-- 数据库的驱动 -->
        <property name="hibernate.format_sql">false</property><!--打印sql语句  -->
        <property name="show_sql">true</property><!--打印sql格式-->
        
        <property name="hbm2ddl.auto">create</property>

<mapping resource="com/ss2h/domain/Users.hbm.xml" />
<mapping resource="com/ss2h/domain/Client.hbm.xml" />
<mapping resource="com/ss2h/domain/Dept.hbm.xml" />
<mapping resource="com/ss2h/domain/Emp.hbm.xml" />
    </session-factory>

</hibernate-configuration>

spring_struts_Hiber.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/aop
          http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
          http://www.springframework.org/schema/tx 
          http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-3.0.xsd">
          
<!--          <aop:aspectj-autoproxy />-->
      <context:component-scan base-package="com.ss2h" >
       <context:include-filter type="regex" expression=".service.*.*"/>
     </context:component-scan> 
<!--     <tx:annotation-driven transaction-manager="transactionManager"/> -->
          
     <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="configLocation"  
            value="classpath:hibernate.cfg.xml">  
        </property>
    </bean>

<bean id="transactionManager"  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
   </bean>
   
    <aop:config>
    <aop:pointcut id="userServiceMethods" 
            expression="execution(* com.ss2h.service.*.*(..))"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="userServiceMethods"/>
  </aop:config>

   <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
      <tx:method name="*" propagation="REQUIRED"/>
    </tx:attributes>
  </tx:advice>
<!---->
   <bean id="userimphiber" class="com.ss2h.dao.Daoimp.UserHiberImp">
      <property name="sessionFactory" ref="sessionFactory"></property>
   </bean>
   <bean id="userservimp" class="com.ss2h.service.serviceimp.UserServimp">
     <property name="userDao" ref="userimphiber"></property>
   </bean>
   
   <bean id="userAction" class="com.ss2h.action.UserAction">
    <property name="userservimp" ref="userservimp"></property>
   </bean>
  
  <bean id="zjls" class="com.ss2h.util.Util">
  <property name="sessionFactory" ref="sessionFactory"></property>
  </bean>
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Client~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  -->

<bean id="clienthiberimp" class="com.ss2h.dao.Daoimp.ClientHiberimp">
      <property name="sessionFactory" ref="sessionFactory"></property>
   </bean>
   <bean id="clientservimp" class="com.ss2h.service.serviceimp.ClientServimp">
     <property name="clientdao" ref="clienthiberimp"></property>
   </bean>
  <bean id="clientAction" class="com.ss2h.action.ClientAction">
  <property name="clientservimp" ref="clientservimp"></property>
  </bean>
  <!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~dept~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  -->
  <bean id="deptdao" class="com.ss2h.dao.Daoimp.DeptdaoImp">
  <property name="sessionFactory" ref="sessionFactory"></property>
  </bean>
  <bean id="deptSerimp" class="com.ss2h.service.serviceimp.DeptServimp">
  <property name="deptdao" ref="deptdao"></property>
  </bean>
  <bean id="deptAction" class="com.ss2h.action.DeptAction">
  <property name="deptSerimp" ref="deptSerimp"></property>
  </bean>
  <!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Employee~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  -->
  <bean id="empdao" class="com.ss2h.dao.Daoimp.EmployeedaoImp">
  <property name="sessionFactory" ref="sessionFactory"></property>
  </bean>
  <bean id="empservimp" class="com.ss2h.service.serviceimp.EmployeeServimp">
  <property name="empdao" ref="empdao"></property>
  </bean>
  <bean id="empAction" class="com.ss2h.action.EmployeeAction">
  <property name="empservice" ref="empservimp"></property>
  <property name="deptSerimp" ref="deptSerimp"></property>
  </bean>
</beans>

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<!--<include file="*****.xml"></include>    加载*****.xml文件-->
<!--<constant name="struts.ui.theme" value="simple"></constant>-->
<!--<constant name="struts.locale" value="zh_CN"/>--><!--加载语言环境-->
<!--<constant name="struts.locale" value="en_US"/>-->
<!-- <constant name="struts.custom.i18n.resources" value="message"/>加载message这一类语言 -->
 <!--<constant name="struts.i18n.encoding" value="utf-8"/>--><!--编码格式-->
 <constant name="struts.ui.theme" value="simple" />
 <constant name="struts.objectFactory" value="spring"></constant><!-- 引入spring中的UserAction -->
 
<package name="userPack" extends="struts-default">
<action name="userAction_*" class="userAction" method="{1}">
  <result name="save" type="redirectAction">userAction_findAll</result>
  <result name="findId">/crud/user/add.jsp</result>
  <result name="findAll">/crud/user/userList.jsp</result>
  <result name="del" type="redirectAction">userAction_findAll</result>
  <result name="update">/crud/user/add.jsp</result>
  <result name="updateid">/crud/user/add.jsp</result>
</action>

<action name="ClientAction" class="clientAction">
  <result >/crud/user/tA.jsp</result>
  <result name="cuowu">/client/cuowu.jsp</result>
  <result name="save">/client/index.jsp</result>
</action>

<action name="DeptAction_*" class="deptAction" method="{1}">
<result name="save" type="redirectAction">DeptAction_getDepts</result>
<result name="select">/crud/dept/deptadd.jsp</result>
<result name="findname">/crud/dept/select.jsp</result>
<result name="del" type="redirectAction">DeptAction_getDepts</result>
<result name="depts">/crud/dept/deptlist.jsp</result>
</action>

<action name="EmpAction_*" class="empAction" method="{1}">
<result name="save" type="redirectAction">EmpAction_employee</result>
<result name="select">/crud/employee/select.jsp</result>
<result name="dept">/crud/employee/empadd.jsp</result>
<result name="findname">/crud/employee/select.jsp</result>
<result name="del" type="redirectAction">EmpAction_employee</result>
<result name="findId">/crud/employee/empadd.jsp</result>
<result name="empall">/crud/employee/emplist.jsp</result>
</action>

</package>    
</struts>
  相关解决方案