"Interview" "Spring FAQ" "01"

Source: Internet
Author: User

Spring is an open source framework, and spring is a lightweight Java development framework that emerged in 2003 by Rod Johnson in his expert one-on-one development and design Part of the concept and prototype derived from the elaboration. It is created to address the complexities of enterprise application development. One of the main advantages of the framework is its layered architecture, which allows the user to choose which component to use, while providing an integrated framework for Java EE application development. Spring uses basic JavaBean to accomplish things that were previously only possible by EJBS. However, the use of spring is not limited to server-side development. From the standpoint of simplicity, testability, and loose coupling, any Java application can benefit from spring. The core of spring is control inversion (IoC) and facet-oriented (AOP). In short, spring is a layered, javase/eefull-stack (one-stop) lightweight, open-source framework.
Spring Therefore, spring is often asked in the interview, this is a summary of some of spring's problems, learning and reference.
1. The main features of spring are dependency in (DI) and aspect-oriented programming (AOP). 2. What is Dependency injection

Dependency Injection (dependencyinjection) and control inversion (inversionof controls) are the same concept. The implication is that when a role (possibly a Java instance, the caller) needs the assistance of another role (another Java instance, the callee), the caller's instance is typically created by callers during the traditional program design process. In spring, however, the work of creating the callee is no longer done by the caller, so called control inversion, and the work of creating the callee instance is usually done by the spring container, which is then injected into the caller and, therefore, also called dependency injection.

3. What is tangent-oriented programming

In order to extract the facets in the process of business processing, it is confronted with a step or stage in the process to obtain the isolation effect of the low coupling between the parts of the logic process.

4, in order to reduce the complexity of Java development, Spring has adopted the following 4 key strategies

Lightweight and minimal intrusive programming based on Pojo,

Loosely coupled through dependency injection and interface-oriented

Declarative programming based on facets and conventions,

Reduce boilerplate code with facets and templates.

5. What are the ways of dependency injection?

Interface injection (interface injection) interface injection refers to defining the information to be injected in the interface and completing the injection through the interface.

Set Injection (setterinjection) set injection refers to defining a set method in the class that accepts the injection, and defines the elements that need to be injected in the parameters.

Construct Injection (constructor injection) constructs an injection by defining a construction method in the class that accepts the injection, and defining the elements that need to be injected in the parameters  

6. What are the spring application contexts?

classpathxmlapplicationcontext--loads the context definition from the XML configuration file under the Classpath and treats the application context definition file as a class resource.

Filesystemxmlapplicationcontext the file system to the XML configuration file and load the context definition.

xmlwebapplicationcontext--reads the XML configuration file under the Web application and loads the context definition.

The difference between using Filesystemxmlapplicationcontext and using Classpathxmlapplicationcontext is:

Filesystemxmlapplicationcontext to locate the file under the specified file system path,

Classpathxmlapplicationcontext is to find files under all classpath (including jar files).

7. Bean Life cycle

The following is the bean life cycle of Spring3.

1) Spring instantiates the bean.

2) Spring injects the value and the bean reference into the bean's corresponding attribute.

3) If the bean implements the Beannameaware interface, Spring passes the Bean's ID to the Setbeanname () interface method.

4) If the Bean implements the Beanfactoryaware interface, Spring calls the Setbeanfactory () interface method to pass the Beanfactory container instance in.

5) If the Bean implements the Applicationcontextaware interface, Spring will call the Setapplicationcontext () interface method, passing in the reference to the application context.

6) If the bean implements the Beanpostprocessor interface, spring will call their Postprocessbeforeinitialization interface method.

7) If the Bean implements the Initializingbean interface, Spring will call their Afterpropertiesset () interface method. Similarly, if the bean declares the initialization method using Init-method, the method is also called.

8) If the bean implements the Beanpostprocessor interface, Spring will call their Postporessafterinitilization method.

9) The Bean is ready at this moment. Can be used by the application. They will always reside in the application context. Until the app context is destroyed.

10) If the bean implements the Disposablebean interface, Spring will call its destroy () interface method. Similarly, if the bean declares the destroy method using Destroy-method, the method is called.  

8, Spring3.0 overall module framework:

Core Spring Container: The core part of the spring framework, responsible for the creation, configuration, and management of beans in spring applications. All modules are built on top of the core container.

--Spring's AOP module: In the AOP module, Spring provides rich support for aspect-oriented programming. This module is the basis for the development facets of spring application systems. AOP helps to decouple application objects.

--Data access and integration: Spring's JDBC and DAO modules encapsulate these template-style code, make our database code straightforward, and avoid problems caused by the failure to release database resources. This module constructs a semantic and rich anomaly layer on top of several database service error messages.

--Web and Remote call: Spring not only integrates a variety of popular MVC frameworks, it also has a powerful MVC framework with its web and remote invocation modules, helping to apply the loose coupling of web-layer technologies. The framework provides two forms of servlet-based frameworks for traditional Web applications and Portlet-based applications for using Java Portlet APIs. In addition to user-facing Web applications, the module provides several remote invocation options for building interactions with other applications. The Spring Remote Call service integrates RMI. Hession, Burlap, Jax-WS, and spring also comes with a remote calling framework HTTP Invoker.

--L Test: Spring provides a debug module to test the spring application.

9. Spring Common namespaces:

10. Scope of Bean:

"Interview" "Spring FAQ" "01"

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.