解决方案 »

  1.   

    applicationContext.xml
    <?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:tx="http://www.springframework.org/schema/tx" 
           xmlns:aop="http://www.springframework.org/schema/aop" 
           xsi:schemaLocation="http://www.springframework.org/schema/beans 
               http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
               http://www.springframework.org/schema/tx 
               http://www.springframework.org/schema/tx/spring-tx-2.5.xsd 
               http://www.springframework.org/schema/aop 
               http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">      <!-- 配置数据源对象 -->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
    <property name="url" value="jdbc:oracle:thin:@localhost:1521:oracle" />
    <property name="username" value="wangsheng" />
    <property name="password" value="bdqn" />
    </bean>

    <!-- 注入SessionFactory,这一步就完成了Hibernate与Spring的整合 -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" >
    <ref bean="dataSource" />
    </property>
    <property name="hibernateProperties">
    <props>
    <!-- 设置控制台显示sql代码 -->
    <prop key="hibernate.show_sql">true</prop>
    <!-- 设置控制台显示sql代码格式化 -->
    <prop key="hibernate.format_sql">true</prop>
    <!-- 方言 -->
    <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
    </props>
    </property>
    <!--hibernate实体bean的映射文件,可以配置有多个映射文件 -->
    <property name="mappingResources">
    <list>
    <value>com/bdqn/crm/user/entity/user.hbm.xml</value>
    <value>com/bdqn/crm/user/entity/department.hbm.xml</value>
        <value>com/bdqn/crm/user/entity/role.hbm.xml</value>
    </list>
    </property>
    </bean> <!--基本bean的配置 ,添加业务类的beanFactory-->
    <bean id="UserDaoImpl" class="com.bdqn.crm.user.dao.impl.UserDaoImpl">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <bean id="user" class="com.bdqn.crm.user.entity.User"></bean>
    <bean id="department" class="com.bdqn.crm.user.entity.Department"></bean> <!--配置service自动装配  -->
    <bean id="UserServiceImpl" class="com.bdqn.crm.user.service.impl.UserServiceImpl">
    <property name="userdao" ref="UserDaoImpl"></property>
    </bean>

    <!--配置用户信息的操作-->
    <!-- 用户信息操作 -->
    <bean id="UserAction" class="com.bdqn.crm.user.action.UserAction" scope="prototype">
    <property name="userService" ref="UserServiceImpl"></property>
    <property name="pagesUser" ref="user"></property>
    </bean>
    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>   
                <tx:method name="save*" propagation="REQUIRED" />   
                <tx:method name="delete*" propagation="REQUIRED" />   
                <tx:method name="update*" propagation="REQUIRED" />  
                <tx:method name="insert*" propagation="REQUIRED" /> 
                <tx:method name="*" read-only="true"/>   
            </tx:attributes>  
    </tx:advice>

    <aop:config proxy-target-class="true">
        <aop:pointcut id="allManagerMethod"  
                expression="execution(* com.bdqn.crm.*.service.impl.*.*(..))"/>  
            <aop:advisor advice-ref="txAdvice"  
               pointcut-ref="allManagerMethod" />  
    </aop:config>

    </beans>
      

  2.   

    struts.xml:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
    <struts>
    <constant name="struts.devModel" value="true" />
    <constant name="struts.i18n.encoding" value="UTF-8" />
    <constant name=" struts.objectFactory " value="spring" />
    <constant name="struts.enable.DynamicMethodInvocation" value="false"></constant>
    <include file="struts-default.xml"></include>
    <package name="default" namespace="/" extends="struts-default">
            <!--用户登录、注销  -->
            <action name="user*"  class="UserAction"  method="{1}">
                <result name="login">/pages/main.jsp</result>
                <result name="login_out">/pages/login.jsp</result>
            </action>
    </package>
    </struts>   
      

  3.   

    已经解决了,方案如下:
    先以myeclipse为例:
    1、确保tomcat下的webapp和work文件夹只有目标项目(还有两个空文件夹。),crm为目标项目。
    说明:tomcat这两个文件夹有时是不自动删除其他项目,原理还有待了解。在调试框架考虑这个地方,不然可能会出现有些莫名其妙的异常,主要是其他项目加载报错,而非目标项目。
    2、hibernate配置文件的文件头要确保正确:
    http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd
    3、包是否冲突,有多余,或者少了包。