Summary of Spring face questions

Source: Internet
Author: User

What is the core function of spring? What are the core reasons for using the spring framework?

There are three core components in the Spring framework: Core, Context, and Beans. One of the core components is beans, and spring provides the core function of Bean Factory.

One of the core issues that spring solves is the transition of dependency between objects into a configuration file, which is spring's dependency injection mechanism. This injection mechanism is managed in the IOC container.

The Bean component is under Spring's Org.springframework.beans package. This package mainly solves the following functions: Bean definition, bean creation, and parsing of the bean. The only thing that matters to spring users is the creation of beans, and the other two are done by the spring internal mechanism. The Spring Bean was created using a typical factory model, and his top-level interface was beanfactory.

Beanfactory has three subcategories: Listablebeanfactory, Hierarchicalbeanfactory, and Autowirecapablebeanfactory. But from this we can find that the final default implementation class is Defaultlistablebeanfactory, and he implements all the interfaces. So why define so many levels of interfaces? Refer to the source code and description of these interfaces found that each interface has his use of the occasion, it is mainly to distinguish between Spring in the process of the object during the transfer and conversion process, the object of the data access restrictions. For example, the Listablebeanfactory interface indicates that these beans are a list, and hierarchicalbeanfactory indicates that the beans are inherited, that is, each bean may have a parent bean. The Autowirecapablebeanfactory interface defines the automatic assembly rules for the Bean. These four interfaces collectively define the collection of beans, the relationships between beans, and the bean behavior.

The Bean definition is a complete description of all the information in the <bean/> node that you define in the Spring configuration file, including the various child nodes. When spring successfully parses a <bean/> node that you define, within spring, he is transformed into a Beandefinition object. All subsequent operations are done on this object. The parsing process of the Bean is very complex and the function is very thin, because there are many places that need to be expanded, and there must be sufficient flexibility to cope with possible changes. The parsing of the Bean is mainly the parsing of the Spring configuration file.

Two, spring framework is divided into which seven modules, the main function of each module is what?

Seven modules, as follows:

1. The Spring Core:core package is the most fundamental part of the framework, providing IOC and dependency injection characteristics. The basic concept here is beanfactory, which provides a classic implementation of the factory pattern to eliminate the need for procedural singleton patterns and really allows you to isolate dependencies and configurations from the program logic.

2.Spring Context: The context package, built on the core package, provides a framework for object access, some like the Jndi registrar. The context wrapper package is characterized by the beans package and adds support for internationalization (i18n), event propagation, the way resources are loaded, and the transparent creation of the context, such as through a servlet container.

3. Spring Dao:dao (Data Access Object) provides a JDBC abstraction layer that eliminates lengthy JDBC encoding and resolves database vendor-specific error codes. Also, the JDBC package provides a better declarative transaction management approach than programmatic, not only for specific interfaces, but also for all pojos (plain old Java objects).

The 4.Spring Orm:orm package provides an integrated layer of commonly used "object/relationship" mapping APIs. These include JPA, JDO, Hibernate, and IBatis. With the ORM package, you can mix the "object/relationship" mappings with all of the spring-provided features, such as the simple declarative transaction management mentioned earlier.

The AOP package for 5.Spring aop:spring provides an aspect-oriented programming implementation that conforms to the AOP Alliance specification, allowing you to define, for example, method interceptors (method-interceptors) and Pointcuts (pointcuts), logically, Thereby weakening the functional coupling of the code, clearly separated away. Also, with the Source-level metadata feature, you can incorporate various behavioral information into your code.

Web Packages in 6.Spring web:spring provide the underlying integration features for web development, such as multi-party file uploads, and the use of servlet listeners for IOC container initialization and web-based applicationcontext. When using spring with webwork or struts, this package enables spring to be combined with other frameworks.

The MVC wrapper package in 7.Spring Web Mvc:spring provides a model-view-controller (MVC) Implementation of the Web application. The spring MVC Framework does not simply provide a traditional implementation, it provides a clear separation model between the domain model code and the Web form. Also, other features of the spring framework can be used.

Iii. What are the three core ideas in the spring framework?

DI (Dependency injection), IOC (inversion of Control), AOP (plane-oriented programming)

Iv. the IOC concept and how the IOC operates in the spring container.

Ioc:inversion of control, inversion of controls. In Java development, IOC means that the class you have designed is given to the system to control, not within your class, which is called control inversion, that is, the instance of the called class is created by the original invocation class control, and the destruction is now transformed into a container managed by spring.

V. How the Spring container manages the bean's life cycle (e.g., bean initialization method, bean destruction method)

Created: <bean name= "" class= "" Extra Properties >

Initialize: Configure Init-method/Implementation Interface Initializingbean

Call: Context.getbean (), making a call to the method

Destroy: Configure destroy-method/to implement Disposablebean interface

The concept of Di and the injection in spring framework are several ways. What problems must be noticed when using constructs to inject objects, and the sequence of sequential processes that are executed when the value injection and the construction injection exist simultaneously

Injection method:

    • Interface Injection
    • attribute injection [Set/get of attributes]
    • Construction injection [construction method injection]

When using a constructor dependency injection, spring guarantees that all objects dependent on all objects are instantiated before instantiating the object. When using the Set method dependency injection, spring instantiates the object first and then instantiates all dependent objects.

When the setpoint injection is present at the same time as the construction injection, the set injection is performed before the construction injection.

What does the property mean when using di injection, how to inject if the property refers to another bean, and how to set if the reference is a string.

When using Di injection, the property represents the attribute of the injected class, and if the other bean is applied with a ref attribute to indicate the name of the referenced bean, if it is a reference string, use the Value property. Such as:

<property name= "Userdao" ref= "name of the referenced bean"/>

<property name= "username" value = "string"/>

Eight, Spring AOP related several aspects of the questions

1. What are the notification types for spring?

2. What is the difference between a target object implementation interface and a target object that does not implement an interface?

3. Please describe the difference between the JDK dynamic agent and the Cgli agent.

4. What is the role of Proxyfactorybean?

5. Describe the principle of automatic proxy in spring?

5. Write out what are the three elements you specify to create a proxy object?

6. What are the two ways to write an agent?

7. Please outline: What is AOP?

8. Describe the AOP core?

9. Describe the meaning of AOP transactions?

IX. issues related to the sping IOC

1. Please outline the working mechanism of spring?

2. Please answer why do you use spring's working mechanism?

3. Please describe what spring is?

4. Describe the composition of spring?

5. Briefly describe what features the spring container provides?

6. In spring, there are several ways to inject beans, what are they?

7. Please outline: scope of Spring bean?

8. Please describe the advantages of setting value injection?

9. Please describe the advantages of construction injection?

10. Say the three ways bean factory creates beans?
11. How do you write the life cycle of the bean?

12. Please outline your understanding of the IOC?

13. Please answer: What is the greatest advantage of IOC?

14. Describe the type of IOC?

What is the difference between dependency injection and traditional programming in spring?

    1. The IOC concept and how the IOC operates in the spring container.
    2. How the Spring container manages the bean's life cycle (such as the Bean's initialization method, the Bean's destruction method)
    3. The concept of Di and the injection in spring framework are several ways. What problems must be noticed when using constructs to inject objects, and the sequence of sequential processes that are executed when the value injection and the construction injection exist simultaneously
    4. When using Di injection, the property represents what it means, if the property refers to another bean, how to inject, if the reference is a string, how to set.
    5. There are several ways to get a connection pool in the spring framework. When Jndi and DBCP exist at the same time, the problem will not occur, if not at the same time, please explain why
    6. What objects must be injected into the template when using spring's jdbctemplate to manipulate the data, and the template should not manually close the database connection
    7. JdbcTemplate's queryForList method gets the list collection, which is why each object in the list collection is of the data type, and how the El expression is used in the JSP page.
    8. What are the benefits of the concept of AOP and the use of AOP mechanisms? There are several ways to implement AOP in Java programming
    9. There are several transaction processing in the spring framework. Please explain the difference between the two separately
    10. What is the total interface for a programmatic transaction? What are the core class objects of spring transactions that need to be used with programmatic transactions
    11. Spring's declarative transactions can generate proxy interfaces for ordinary classes, can you use Try/catch in your code to catch exceptions, and if not, explain why
    12. When using Transactionproxyfactorybean to generate transactional physics for a bean, the settings for which property values are required

1. Outline your understanding of the IOC (inversion of Control) and describe several ways to implement DI (Dependency injection) in spring.
2, spring advocates interface-oriented programming, please tell me what you understand it, what is the benefit of it.
3. What are the scopes of spring beans?
4. Briefly describe the differences between spring framework and struts, and what are the best ways to integrate spring and struts?
5, rails in a large number of convention over the configuration of the idea, SPRINGMVC after 2.0 also introduced the COC, please briefly describe Springmvc's COC.
6, the difference between the update () and Saveorupdate () in Hibernate, the difference between the load () and get () of the session.
7. Spring provides good support for a variety of ORM frameworks, with a simple description of how hibernate is used in spring, combined with transaction management.
8. Briefly describe the transaction propagation behavior and isolation level of spring.

Answer:
1, Hollywood principles-Don't call me, I'll call you. IOC moves the created responsibilities from the application code into the framework. Spring provides support for setter injection and construction method injection. (see http://martinfowler.com/articles/injection.html, and http://www.redsaga.com/spring_ref/2.0/html/beans.html# Beans-factory-collaborators)
2, in an object-oriented system, the various functions of the system are done by many different objects. In this case, it is less important for the system designer to implement their own internal objects, and the collaboration between the objects becomes the key to the design of the system. Small to different classes of communication, large to the interaction between the modules, at the beginning of the system design is to focus on, which is the main work of the system design. (See http://deve.blogdriver.com/deve/415943.html)
3. Singleton, prototype, request, session, global session, custom (see the scope of section 3.4 Beans for Spring Framework 2.0 reference)
4. Spring is a complete one-stop frame, and struts is only the MVC framework and focuses on C in MVC. Spring has three ways to integrate struts: Use Spring's Actionsupport class to integrate struts, and spring delegatingrequestprocessor to cover struts requestprocess Or, delegate Struts action management to the Spring framework, which is the best action delegate. (see Using spring to better handle struts actions)
Spring 2.0 adds a new way: Autowiringrequestprocessor. (See http://www.javaeye.com/topic/24239)
5, the controller bean can be directly mapped to the address by the end of the controllers, model Modelandview can not specify the key name, can be automatically based on the URL to obtain the view name. (See the Spring Framework 2.0 Reference, section 13.11, Convention precedence Principles)
6, the Saveorupdate () method can implement the function of update (), but there are more steps, as follows:
If the object has been persisted in the session, no action is taken;
Object identifier attribute (identifier property) does not exist in the database or is a temporary value, call the Save () method to save it;
Throws an exception if another object in the session has the same identifier;
If none of the above matches, call Update ().
The Session.load/get method can read records from the database based on the specified entity class and ID, and returns the corresponding entity object. The difference is:
If a qualifying record is not found, the Get method returns NULL, and the load method throws a objectnotfoundexception;
The Load method returns an instance of the entity's proxy class, and the Get method always returns the entity class directly;
The Load method can take full advantage of the existing data in the internal cache and the level two cache, while the Get method only makes data lookups in the internal cache, and if no corresponding data is found, it passes through the level two cache and directly invokes SQL to complete the data read.
7, define DataSource in the context, create Sessionfactoy, set parameters, DAO class inherits Hibernatedaosupport, implements concrete interface, obtains hibernatetemplate for concrete operation from it. If you encounter opensessioninview problems in use, you can add Opensessioninviewfilter or opensessioninviewinterceptor. (see Spring Framework 2.0 Reference, section 12.2, Hibernate)
Declarative transactions need to declare the transaction manager, set <tx:advice> specify properties in the context, and <aop:config> determine <aop:advisor> and <aop:pointcut>. (see section 9.5 Declarative transaction management for Spring Framework 2.0 reference)
8. The communication behavior is divided into six kinds:
propagation_required– supports the current transaction and creates a new transaction if there is no current transaction. This is the most common choice.
propagation_supports– supports the current transaction and is executed in a non-transactional manner if no transaction is currently in use.
The propagation_mandatory– supports the current transaction and throws an exception if there is no current transaction.
propagation_requires_new– a new transaction, suspending the current transaction if a transaction is currently present.
The propagation_not_supported– executes the operation in a non-transactional manner, suspending the current transaction if a transaction is currently present.
The propagation_never– is executed in a non-transactional manner and throws an exception if a transaction is currently present.
Isolation level:
Isolation_default This is a platfromtransactionmanager default isolation level, which uses the default transaction isolation level of the database. The other four correspond to the isolation level of JDBC
Isolation_read_uncommitted This is the lowest isolation level for transactions, and it allows a transaction to see uncommitted data for this transaction. This isolation level produces dirty reads, non-repeatable reads, and Phantom reads.
Isolation_read_committed guarantees that a transaction modified data is committed before it can be read by another transaction. Another transaction cannot read uncommitted data for the transaction. This level of transaction isolation avoids dirty reads, but non-repeatable reads and phantom reads can occur.
Isolation_repeatable_read This transaction isolation level prevents dirty reads and cannot be read repeatedly. However, Phantom reads may occur. In addition to ensuring that one transaction cannot read uncommitted data from another transaction, it ensures that the following conditions are avoided (non-repeatable read).
Isolation_serializable This is the most cost-effective, but most reliable, transaction isolation level. Transactions are processed for sequential execution. In addition to preventing dirty reading, non-repeatable reading, but also avoids phantom reading.

Summary of Spring face questions

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.