Summary of the interview questions of Spring and SPRINGMVC

Source: Internet
Author: User
Tags aop constructor error handling
Summary of the interview questions of Spring and SPRINGMVC

Application scenarios, AOP principles, benefits of AOP in 1.Spring.

A: Aop--aspect oriented programming is programming for facets and is used to encapsulate crosscutting concerns in the following scenarios:

Authentication permissions, Caching cache, context passing content delivery, error handling Errors handling lazy loading lazy loading, debugging debugging, logging, tracing, Profiling and monitoring record tracking optimization calibration, performance optimization performance optimization, persistence persistence, Resource pooling resource pool, synchronization synchronization , Transactions transactions

Principle: AOP is the aspect-oriented programming, which is to add unified function to the program through dynamic proxy, and to solve some public problems centrally.

Pros: 1. Good isolation coupling between individual steps is greatly reduced
2. Source code Independent, and then expand the functionality of the source and do not modify the operation

The role and principle of IOC in 2.Spring. The process of creating an object.

Answer: Ioc--inversion of control inversion. When a role needs to be assisted by another role, the caller's instance object is typically created by callers during a traditional program design process. But the work of creating the callee in spring is no longer done by the caller, so called control inversion. The work of creating the callee is done by spring, which is then injected directly into the caller's use.

3. Introduction to the Spring framework

It is a one-stop (full-stack full-stack) framework that provides a complete set of solutions from the presentation layer-SPRINGMVC to the business layer-spring to the persistence layer-springdata. We can only use the spring one framework in the project, it can provide the expression layer of the MVC framework, the persistence layer of the DAO framework. Its two core IOC and AOP provide support for our program decoupling and code simplicity and ease of maintenance.

4.Spring common annotations for creating objects.

Answer: @Component @controller@ service@ Repository

Design patterns used in 5.Spring

Answer: Simple factory, factory method, Singleton mode, adapter, wrapper, agent, observer, policy, template method

Detailed Description: Please refer to this Weibo: develop common design patterns

The advantages of 6.Spring.

A: 1. The coupling between components is reduced, and the decoupling between each layer of software is realized.
2. Can use many services that are easy to provide, such as transaction management, message service, etc.
3. The container provides a singleton mode support
4. The container provides AOP technology, it is easy to implement such as permission interception, run-time monitoring and other functions
5. The container provides many auxiliary classes, which can accelerate the development of the application
6.spring provides integrated support for mainstream application frameworks, such as Hibernate,jpa,struts
7.spring is a low-intrusive design with very low code pollution
8. Independent of various application servers
The 9.spring di mechanism reduces the complexity of business object substitution
10.Spring is highly open and does not force applications to rely entirely on spring, and developers are free to select part or all of spring

What is the difference between the scope of the 7.Spring bean.

Beans in a spring container can be divided into 5 ranges. The names of all scopes are self-explanatory, but to avoid confusion, let's explain:

Singleton: This bean range is the default, and this range ensures that no matter how many requests are received, there is only one instance of the bean in each container, and the singleton pattern is maintained by the Bean factory itself.

Prototype: The prototype range is the opposite of a singleton range, providing an instance for each bean request.

Request: an instance of each network request from the client is created within the scope of the requesting bean, and after the request is completed, the bean is invalidated and reclaimed by the garbage collector.

Session: Similar to the request scope, ensure that there is an instance of the bean in each session, and the bean will expire after the session expires.

Global-session:global-session is associated with portlet applications. When your app is deployed to work in a portlet container, it contains many portlets. If you want to declare that all portlets share a global storage variable, then this global variable needs to be stored in global-session.

The global scope has the same effect as the session scope in the servlet.

There are several ways to manage transactions in 8.Spring.

Answer: There are two ways:

1, programming transactions, hard coding in the code. (Not recommended)

2, declarative transactions, configured in the configuration file (recommended)

Declarative transactions are divided into two types:

A, XML-based declarative transactions

b, annotation-based declarative transactions

What are the automatic assembly methods in 9.spring?

Answer: 1, No: Automatic assembly is not enabled.

2, ByName: The name of the property to find the JavaBean-dependent object and inject it. For example, if the class computer has a property printer, specifying that its Autowire property is ByName, the Spring IOC container looks for a bean with Id/name property printer in the configuration file and injects it using the Seter method.

3. Bytype: Finds and injects JavaBean-dependent objects through the type of the property. For example, if the class computer has an attribute printer and the type is printer, the Spring IOC container will look for the bean with the class attribute bytype and inject it with the printer method after specifying its Autowire property as Seter.

4, constructor: Pass Bytype like, is also through the type to find dependent objects. The difference from Bytype is that it is not injected using the Seter method, but instead uses a constructor injection.

5. AutoDetect: Automatic choice of injection mode between Bytype and constructor.

6. Default: Determined by the Default-autowire attribute of the parent tag <beans>.

The core classes in 10.spring have those, each of which has a role.

Answer: beanfactory: Create a new instance, you can implement the singleton mode

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.