The SSH (sturts2_spring_hibernate) framework builds spring

Source: Internet
Author: User

One, Spring summary:

⑴, Spring is a lightweight Java development framework, the main role is to manage the instance (can solve the Java class new object problem, save memory resources. ) and reduce the coupling between the code to facilitate the modularity of the code.

⑵, the modular chemistry that facilitates the code, is also called the IOC (inversion of Control). However, Di is widely used.

Second, Spring Construction:

⑴, importing related jar packages:

①, download good spring and extract it to find the Lib directory will be in addition to Javadoc and sources jar package all import project, and find the Struts2-spring-plugin jar package and the Commons-logging Jar package import project in the Struts decompression package lib directory. As follows:

    

②, make the relevant file configuration in Web. xml:

      

③, declare in Struts.xml: The destination is that all instance creation is given to spring (using spring to manage the instance):

       

④, create a new XML file in Project SRC, which is applicationcontext.xml, where Spring's bean is configured:

⑴, first need to beans label. Beans tag is the basic configuration header information, basically does not change, in addition to the differences between the version of the version information needs to be changed, the other basic changes are small.

<beans xmlns= "Http://www.springframework.org/schema/beans"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xmlns:p= "http://www.springframework.org/schema/p"
xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"
xmlns:context= "Http://www.springframework.org/schema/context"
Xmlns:jee= "Http://www.springframework.org/schema/jee"
xmlns:tx= "Http://www.springframework.org/schema/tx"
Xsi:schemalocation= "
HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
Http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.2.xsd
Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd ">

        

< The configuration of the bean instance here after!--. -

<beans>

⑵, followed by the configuration bean instance, the following is the configuration of the example:

        

· The id attribute in the bean tag is the name of the bean, and it may be necessary to use another instance in one instance, which is the reference name.

· The class attribute in the bean tag is the one that points to it, which is the new instance of the class, but it does it by itself, but the bean helps us solve it.

· The scope in the bean tag is the creation of the instance, such as:

Singleton: Single instance, in bean stateless use.

Prototype: Each request to this bean will create an instance.

Request: Each HTTP request will have its own bean instance, similar to prototype.

Session: In an HTTP session, a bean definition corresponds to a bean instance.

Global session: In a global HTTP session, a bean definition corresponds to a bean instance. Typically, this is only valid when using the Portlet context.

①, this line of code means: first, in action. The Actionservice class needs to have a member property of MS, which defines the set method of this property (spring will help inject this instance), and the type is a services. The type of myserviceimp or the interface type of this class, as follows:

  

Second, this property references an instance of the following Bean's ID of myserviceimp.

Finally, the final function of this sentence is to inject a myserviceimp instance of this MS member attribute.

        

②, this code means: New out of a util. An instance of Myconnectionimp, and each time the bean is requested, it will be a new instance.

The SSH (sturts2_spring_hibernate) framework builds spring

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.