Learn a bit about the integration of Java spring with Struts2 and hibernate every day __java

Source: Internet
Author: User
Struts2 and Spring consolidation
The integration of 1.STRUTS2 and spring is mostly about handing the action in struts to spring to manage the first step: adding an Action class bean to the spring's configuration file (Useraction, for example) can also not write directly in the configuration file Using annotations in the action class can also <bean name= "useraction" class= "Com.xxx.action.UserAction" scope= "prototype" ></bean> Two steps: There are two ways to configure in Struts.xml one is semi-integration and the other is complete integration first introduces two kinds of constants <!--struts.objectfactory=spring default is SPRI Ng says let Spring manage struts's action--> <!--Struts.objectFactory.spring.autoWire = name let spring pair
         The dependency of the action is injected through the name to inject--> <!--the first way to integrate (semi-integrated) the struts configuration file does not need to be modified so that the action is created or struts complete Spring is only responsible for dependency management does not recommend a second full integration (full integration) Replace the class of action in the struts configuration with the bean name in the spring container to let Spring fully manage all a
        Ction and dependencies are partially integrated and fully integrated--> <package name= "action" namespace= "/" extends= "> <action name= "useraction_*" class= "com.xxx.action.UserAction" method= "{1}" > <result name= "Success" & gt;/index.jsp</result&Gt </action> </package> <package name= "action" namespace= "/" extends= "Struts-default" > < Action name= "useraction_*" class= "useraction" method= "{1}" > <result name= "Success" >/index.jsp</res ult> </action> </package> Note: Remember to configure STRUTS2 core filters and spring listeners in Web.xml
Spring and Hibernate consolidation
2.Spring integration with Hibernate first step: Add Hibernate Configuration <!--in spring's configuration file because the framework provides a class file that cannot be used with annotations, you must manually configure the Bean--> <!- -Integration hibernate actually let spring take over sessionfactory--> <bean name= "Sessionfactory" Org.springframework.orm.hibernate5.LocalSessionFactoryBean > <!--This property is used to set the jdbc correlation parameter--> <propert Y name= "hibernateproperties" > <props> <prop key= "Hibernate.connection.driver_class ">com.mysql.jdbc.Driver</prop> <prop key=" Hibernate.connection.password ">123456</prop&gt
                ; <prop key= "Hibernate.connection.url" >jdbc:mysql:///MyDB</prop> <prop key= "Hibernate.connect" Ion.username ">root</prop> <prop key=" Hibernate.dialect ">org.hibernate.dialect.mysql5innodbd ialect</prop> <prop key= "Hibernate.show_sql" >true</prop> <prop key= "h Ibernate.format_sql ">true</prop&Gt
        <prop key= "Hibernate.hbm2ddl.auto" >update</prop> </props> </property> 
<!--Specify the path to the mapping file--> <property name= "mappingdirectorylocations" value= "Com/lanou/bean" ></property>
    Note: When configuring Hibernate in the spring's configuration file. 1. Each attribute must be preceded by a hibernate prefix because these operations are still hibernate in execution only to spring to manage 2. And thread bindings get the implementation of the current session do not add because the session life cycle has been handed Sprig to manage.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.