SSH

web.xml<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath:dao.xml</param-value>
  </context-param>
   <filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
    <listener>
   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
</web-app>

解决方案 »

  1.   

    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>
    <!-- 开启自动由spring来管理action对象, struts2和spring自动集成 -->
    <constant name="struts.objectFactory" value="spring"></constant>

    <package name="wossPackage" extends="struts-default">
    <action name="user" class="com.briup.woss.web.action.UserAction" method="login">
    <result name="success">/index.jsp</result>
    </action>
    </package>
    </struts>
      

  2.   

    dao.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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    <!-- 配置数据源 -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName">
    <value>oracle.jdbc.driver.OracleDriver</value>
    </property>
    <property name="url">
    <value>jdbc:oracle:thin:@127.0.0.1:1521:XE</value>
    </property>
    <property name="username">
    <value>wood</value>
    </property>
    <property name="password">
    <value>wood</value>
    </property>
    </bean>
    <!-- 配置sessionFactory工厂让spring管理 -->
    <bean name="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"></property>
    <property name="mappingResources">
    <list>
    <value>com/briup/woss/pojo/Admins.hbm.xml</value>
    <value>com/briup/woss/pojo/Permission.hbm.xml</value>
    <value>com/briup/woss/pojo/Products.hbm.xml</value>
    <value>com/briup/woss/pojo/Productstype.hbm.xml</value>
    <value>com/briup/woss/pojo/Roles.hbm.xml</value>
    <value>com/briup/woss/pojo/Users.hbm.xml</value>
    <value>com/briup/woss/pojo/UserServices.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    </props>
    </property>
    </bean>

    <!-- 事物管理器hibernateTransactionManager -->
    <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>

    <!-- 配置hibernateTemplate模板 -->
    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
    <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>

    <!-- 配置dao成对象 -->
    <bean id="billingDao" class="com.briup.woss.dao.impl.BillingDaoImpl">
    <property name="hibernateTemplate" ref="hibernateTemplate"></property>
    </bean>
    <bean id="businessDao" class="com.briup.woss.dao.impl.BusinessDaoImpl">
    <property name="hibernateTemplate" ref="hibernateTemplate"></property>
    </bean>
    <bean id="managerDao" class="com.briup.woss.dao.impl.ManagerDaoImpl">
    <property name="hibernateTemplate" ref="hibernateTemplate"></property>
    </bean>
    <bean id="productDao" class="com.briup.woss.dao.impl.ProductDaoImpl">
    <property name="hibernateTemplate" ref="hibernateTemplate"></property>
    </bean>
    <bean id="systemDao" class="com.briup.woss.dao.impl.SystemDaoImpl">
    <property name="hibernateTemplate" ref="hibernateTemplate"></property>
    </bean>
    <bean id="userDao" class="com.briup.woss.dao.impl.UserDaoImpl">
    <property name="hibernateTemplate" ref="hibernateTemplate"></property>
    </bean>

    <!-- 事物的代理工厂bean -->
    <bean id="proxyTxDefintion" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
    <property name="transactionManager" ref="txManager"></property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
    </props>
    </property>
    </bean>

    <!-- 代理serviceBean -->
    <bean id="billingService" parent="proxyTxDefintion">
    <property name="target">
    <bean class="com.briup.woss.service.impl.BillingServiceImpl">
    <property name="billingDao" ref="billingDao"></property>
    </bean>
    </property>
    </bean>
    <bean id="businessService" parent="proxyTxDefintion">
    <property name="target">
    <bean class="com.briup.woss.service.impl.BusinessServiceImpl">
    <property name="businessDao" ref="businessDao"></property>
    </bean>
    </property>
    </bean>
    <bean id="managerService" parent="proxyTxDefintion">
    <property name="target">
    <bean class="com.briup.woss.service.impl.ManagerServiceImpl">
    <property name="managerDao" ref="managerDao"></property>
    </bean>
    </property>
    </bean>
    <bean id="productService" parent="proxyTxDefintion">
    <property name="target">
    <bean class="com.briup.woss.service.impl.ProductServiceImpl">
    <property name="productDao" ref="productDao"></property>
    </bean>
    </property>
    </bean>
    <bean id="systemService" parent="proxyTxDefintion">
    <property name="target">
    <bean class="com.briup.woss.service.impl.SystemServiceImpl">
    <property name="systemDao" ref="systemDao"></property>
    </bean>
    </property>
    </bean>
    <bean id="service" parent="proxyTxDefintion">
    <property name="target">
    <bean class="com.briup.woss.service.impl.UserServieImpl">
    <property name="userDao" ref="userDao"></property>
    </bean>
    </property>
    </bean>
    </beans>
      

  3.   

    只是发个项目的spring配置而已,不必在意。
      

  4.   

    <?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:aop="http://www.springframework.org/schema/aop"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="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-2.5.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
           http://www.springframework.org/schema/tx 
           http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
        <context:annotation-config />
        <context:component-scan base-package="com.aug" />
        
        <bean
            class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="locations">
                <value>classpath:jdbc.properties</value>
            </property>
        </bean>
        
        <bean id="dataSource" destroy-method="close"
            class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName" value="${jdbc.driverClassName}" />
            <property name="url" value="${jdbc.url}" />
            <property name="username" value="${jdbc.username}" />
            <property name="password" value="${jdbc.password}" />
        </bean>
        
        <bean id="sessionFactory"
            class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
            <property name="dataSource" ref="dataSource" />
             <!--
            <property name="annotatedClasses">
                <list>
                    <value>com.aug.model.User</value>
                </list>
            </property>
            -->
            <property name="packagesToScan">
                 <list>
                    <value>com.aug.model</value>
                </list>
            </property>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                    <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                    <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
                <!-- <prop key="current_session_context_class">${current_session_context_class}</prop> -->
                </props>
            </property>
        </bean>
        
        <bean id="txManager"
            class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory" ref="sessionFactory" />
        </bean>
        
        <aop:config>
            <aop:pointcut id="bussinessService"
                expression="execution(public * com.aug.service..*.*(..))" />
            <aop:advisor pointcut-ref="bussinessService" advice-ref="txAdvice" />
        </aop:config>
        <tx:advice id="txAdvice" transaction-manager="txManager">
            <tx:attributes>
                <tx:method name="list*" read-only="true" />
                <tx:method name="find*" read-only="true" />
                <tx:method name="delete*" propagation="REQUIRED" rollback-for="com.aug.exception.ServiceException;" />
                <tx:method name="create*" propagation="REQUIRED" rollback-for="com.aug.exception.ServiceException;" />
            </tx:attributes>
        </tx:advice>
    </beans>
      

  5.   

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
      <display-name>TrainingManagement</display-name>
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
      <listener>
          <listener-class>com.aug.listener.CustomSpringListener</listener-class>
      </listener>
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/applicationContext.xml
            </param-value>
        </context-param>
       
        <filter>
            <filter-name>struts2</filter-name>
            <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        </filter>
         <filter-mapping>
            <filter-name>struts2</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
        
        <filter>
            <filter-name>i18nFilter</filter-name>
            <filter-class>com.aug.filter.I18nFilter</filter-class>
        </filter>
        <filter-mapping>
            <filter-name>i18nFilter</filter-name>
            <url-pattern>/*</url-pattern>
            <url-pattern>/WEB-INF/course/*</url-pattern>
        </filter-mapping>
    </web-app>