整合struts、Hibernate和Spring之配置文件

转载:http://www.gold98.net/blog/article.asp?id=492

struts-config.xml

程序代码

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

<struts-config>
  <data-sources />
  <form-beans >
    <form-bean name="userForm" type="com.zb.struts.form.UserForm" />

  </form-beans>

  <global-exceptions />
  <global-forwards />
  <action-mappings >
    <action
      attribute="userForm"
      input="/userregister.jsp"
      name="userForm"
      path="/user"
      parameter="method"
      scope="request"
      validate="false"
      >
      <forward name="success" path="/registerok.jsp" />
      <forward name="failure" path="/userregister.jsp" />
      <forward name="edituserview" path="/edituser.jsp" />
      <forward name="editok" path="/editok.jsp" />
      <forward name="editfailure" path="/edituser.jsp" />
      <forward name="deleteuserok" path="/deleteok.jsp" />
      <forward name="deleteuserfailure" path="/edituser.jsp" />
    </action>

    </action-mappings>

  <controller>
      <set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor"/>
  </controller>
  <message-resources parameter="com.zb.struts.ApplicationResources" />
  <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
      <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml"/>
  </plug-in>
</struts-config>




applicationContext.xml

程序代码

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>


    <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:@amd02:1521:orcl</value>
        </property>
        <property name="username">
            <value>test</value>
        </property>
        <property name="password">
            <value>test</value>
        </property>
    </bean>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect                </prop>
            </props>
        </property>
        <property name="mappingResources">
            <list>
                <value>com/zb/entity/Users.hbm.xml</value></list>
        </property></bean>
    <bean id="usersDAO" class="com.zb.dao.UsersDAO">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>
   
    <bean id="getListDAO" class="com.zb.dao.GetListDAO">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>
   
    <bean id="userService" class="com.zb.service.UsersService">
        <property name="usersDao">
            <ref local="usersDAO" />
        </property>
    </bean>
    <bean name="/user" class="com.zb.struts.action.UserAction"
        abstract="false" singleton="false" lazy-init="default"
        autowire="default" dependency-check="default">
        <property name="usersService">
            <ref local="userService" />
        </property>
    </bean>


    <bean id="getListService" class="com.zb.service.GetListService"
        abstract="false" singleton="false" lazy-init="default"
        autowire="default" dependency-check="default">
        <property name="getListDao">
            <ref local="getListDAO" />
        </property>
    </bean>
    </beans>


由于web.xml中并没有进行其它配置,就不再列出;

整合struts、Hibernate和Spring之学习笔记一
http://www.gold98.net/blog/article.asp?id=491

上面红色标记内容的作用是:在定义标记action时,不用再给出type属性;

你可能感兴趣的:(spring,oracle,Hibernate,struts,asp.net)