spring+struts2+hibernate integration

The integration steps of the three frameworks:
   * Create a new project
   * Change the coding of the entire project to utf-8
   * Change the entire jsp page to utf-8
   * Guide the package
        web-inf
           lib
               struts
               hibernate
               spring
               db
               junit
   * Build three srcs folder src              cn.itcast.s2sh0909.struts2.action
         where the source code is
             stored cn.itcast.s2sh0909.dao
             cn.itcast.s2sh0909.dao.impl
             cn.itcast.s2sh0909.service
             cn.itcast.s2sh0909.service.impl
             cn.itcast
.s2sh0909.domain
         config stores all configuration files
              struts2
              hibernate
              spring
                 applicationContext.xml
                 applicationContext-db.xml
                 ...........
         test Store the test class
              cn.itcast.s2sh0909.test
   * Write interfaces and classes in the corresponding packages of dao and service layers
   * In applicationContext- Write sessionFactory in the db.xml file
   * Create a new class SessionFactoryTest in the cn.itcast.s2sh0909.test package to test whether the SessionFactory
      is configured correctly
   * Write spring's declarative transaction processing
   * Write dao and service in spring's configuration file
   * Test declarative transaction processing through savePerson method
   * Write action
   * Write struts2 configuration file
   * Write web.xml file
   * Test
              
  
Integration principle:
   * web.xml
      * The spring container is integrated with tomcat in the form of a
           listener <listener>
                <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
           </listener>
           <context-param>
                 <param-name> contextConfigLocation</param-name>
                 <param-value>classpath:spring/applicationContext.xml</param-value>
           </context-param>
      * Integrate struts2 container in the form of
           filter <filter>
                <filter-name>struts2< /filter-name>
                <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
            </filter>

 Description:
   * createContextLoader() loads the spring web container
   * initWebApplicationContext
        * initializes the spring web container
        * loads its configuration file
   * When these two methods are executed, the spring web container is started. In the spring container, the singleton mode The
       bean is instantiated, so the objects and proxy objects of the dao and service layers are generated at this time

When tomcat starts, when
tomcat starts, it does two things:
   * Loads various configuration files       *
   Statically injects some bean
request urls: personAction_savePerson.action
  steps
Relevant configuration to find out how the action is created
      * will go to the constant struts.objectFactory to find out which class created the action
      * will go to the struts-default.xml, struts-plugin.xml, struts.xml files to find struts.objectFactory
      * which configuration The file is loaded at the end, which decides
      * The struts-plugin.xml file is finally found in the struts and spring integration package
             <bean type="com.opensymphony.xwork2.ObjectFactory" name="spring" class="org.apache. struts2.spring.StrutsSpringObjectFactory" />
             <constant name="struts.objectFactory" value="spring" />
      * As you can see from the above, action is created by StrutsSpringObjectFactory, and this class inherits SpringObjectFactory
The beanName in the source code is the value of the class attribute of the action element in the struts2 configuration file, which means that the value of the
   class attribute must be consistent with the id value specified by the bean where the action is located in the spring container

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326674011&siteId=291194637