[Interview] [Spring FAQ summary] [01], spring FAQ 01

Source: Internet
Author: User

[Interview] [Spring FAQ summary] [01], spring FAQ 01
Spring is an open-source framework. Spring was a lightweight Java development framework that emerged in 2003, it is derived from part of the concepts and prototype stated by Rod Johnson in his book "Expert One-On-One J2EE Development and Design. It is created to solve the complexity of enterprise application development. One of the main advantages of the Framework is its layered architecture, which allows users to choose which component to use and provides an integrated framework for J2EE application development. Spring uses the basic JavaBean to complete the previous tasks that may only be completed by EJB. However, Spring is not only used for server-side development. From the perspective of simplicity, testability, and loose coupling, any Java application can benefit from Spring. The core of Spring is IoC and AOP ). In short, Spring is a hierarchical lightweight open-source framework of JavaSE/EEfull-stack (one-stop.
Spring is often asked during the interview. I would like to summarize some questions about Spring and learn and reference them together.
1. Spring depends on DI and AOP ). 2. What is dependency injection?

DependencyInjection and Inversionof Control are the same concepts. Specifically, when a role (possibly a Java instance, caller) needs the assistance of another role (another Java instance, called), in the traditional programming process, generally, the caller creates the called instance. However, in Spring, the creation of the called instance is no longer completed by the caller, so it is called control inversion. The creation of the called instance is usually completed by the Spring container and then injected into the caller, therefore, it is also called dependency injection.

3. What is Aspect-oriented programming?

This interface is used to extract the aspect of a business processing process. It is faced with a certain step or stage in the processing process to achieve the isolation effect of low coupling between parts in the logical process.

4. To reduce Java Development complexity, Spring adopts the following four key strategies:

POJO-based lightweight and minimal invasive programming,

Loose coupling is achieved through dependency injection and interface-oriented,

Declarative Programming Based on aspect and convention,

Reduce the sample code by cropping and templates.

5. How does dependency injection work?

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

Setterinjection Set injection refers to defining a Set method in the class to be injected and defining the elements to be injected in the parameters.

Constructor injection refers to defining a constructor in the class to be injected and defining the elements to be injected in parameters.

6. What are the context of Spring applications?

ClassPathXmlApplicationContext -- loads the context definition from the XML configuration file under the class path, and treats the application context definition file as a class resource.

FileSystemXmlApplicationcontext: obtains the XML configuration file under the file system and loads the context definition.

XmlWebApplicationContext -- read the XML configuration file under the Web application and load the context definition.

The difference between FileSystemXmlapplicationcontext and ClassPathXmlApplicationContext is:

FileSystemXmlapplicationcontext searches for files in the specified file system path,

ClassPathXmlApplicationContext is used to find files in all the class paths (including JAR files.

7. Bean Lifecycle

Below is the Bean lifecycle of spring 3.

1) Spring instantiates Bean.

2) Spring injects values and Bean references into Bean attributes.

3) If Bean implements the BeanNameAware interface, Spring will pass the bean ID to the setBeanName () interface method.

4) if Bean implements the BeanFactoryAware interface, Spring will call the setBeanFactory () interface method and pass the BeanFactory container instance.

5) If Bean implements the ApplicationcontextAware interface Spring, it will call the setApplicationContext () interface method and pass in the reference of the application context.

6) If Bean implements the BeanPostProcessor interface Spring, it will call their postProcessBeforeInitialization interface method.

7) if the Bean implements the InitializingBean interface, Spring will call their afterPropertiesSet () interface method. similarly, if Bean declares the initialization method using init-method, this method will also be called.

8) If Bean implements the BeanPostProcessor interface, Spring will call their postPoressAfterInitilization method.

9) at this moment, beans are ready. They can be used by applications. They will stay in the application context until the application context is destroyed.

10) If Bean implements the DisposableBean interface, Spring will call its destroy () interface method. Similarly, if the Bean declares the destruction method using destroy-method, the method will also be called.

8. Spring3.0 overall module framework:

-- Core Spring container: The core component of the Spring framework. It is responsible for Bean creation, configuration, and management in Spring applications. All modules are built on 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 Spring application system development. AOP can help decouple application objects.

-- Data access and integration: Spring's JDBC and DAO modules encapsulate these template-based codes to make our database code simple and clear, it can also avoid problems caused by database resource release failure. This module builds a semantic and rich exception layer based on the error information of several database services.

-- Web and remote call: Spring not only integrates a variety of popular MVC frameworks, but also provides a powerful MVC framework for its Web and remote call modules, this helps applications improve the loose coupling of Web layer technologies. This framework provides two types of Servlet-based frameworks for traditional Web applications and applications using Java Portlet APIs Based on Portlet. In addition to user-oriented Web applications, this module also provides several options for building remote calls to interact with other applications. Spring Remote Call Service integrates RMI. Hession, Burlap, JAX-WS, Spring also comes with a remote call framework HTTP invoker.

-- L test: Spring provides a debugging module to test Spring applications.

9. Common Spring namespaces:


10. Bean scope:

Related Article

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.