If you do n’t know Spring, then the interviewer of the big factory wo n’t understand why you dare to interview?

You go back and wait for the notice

Interviewer: Seeing that your resume is well written, first introduce yourself briefly?

Me: Good guy! I ’m Xiao Cheng, and I have been working for two and a half years.

, Responsible for maintaining the company ’s two projects ...

Interviewer: hmmm, how much Spring is used in your project?

Me: Okay, basically all can be used. (Usually Baidu uses it)

Interviewer: What do you mean by using Spring's AOP?

Me: (This is my back answer!) AOP is aspect-oriented programming, which can encapsulate logic or responsibilities that are not related to the business but are commonly called by the business module, which is convenient to reduce the repeated code of the system and reduce the coupling between modules , And conducive to future scalability and maintainability.

Interviewer: Well, the understanding is great,

Do you know any Spring extension points?

Me: Extension point? BeanDefinition? BeanFactory?

Interviewer: What else?

Me: It ’s gone.

Interviewer: Well, you know which mainstream frameworks on the market extend Spring, and how to extend it?

Me: I know MyBatis extends Spring! How to expand ... Uh, it's not clear, the others haven't touched it very much and don't understand it well. I also ...

Interviewer: I understand, then you briefly explain the life cycle of Spring bean.

Me: This, I just remember that the process is a bit complicated, specific, I ca n’t remember ...

Interviewer: Then ask you something else,

Does Spring support circular dependencies; under what circumstances?

How to understand beanDefinition in Spring system?

Talk about why Spring needs to use level 3 cache when it comes out of circular dependency?

Some post processors in the Spring system? Can you talk about the main function?

My…

The interviewer looked at his watch: yo, it was already 3pm, so late? Come here today, do you have any questions for me?

Me: Did I hang up?

Interviewer: No no no, please go back and wait for the notice!

Spring is now the most popular java development technology, and its internal source code design is excellent. If you do not know Spring, then the interviewer will probably let you go home and wait for notification.

What is Spring?

There is a construction site where hundreds of people are digging pits with shovels.

If you drive an excavator, one day's work is equivalent to one worker's monthly workload. And this excavator is free and open source, no need to spend money to buy, just need to learn how to operate.

How would you choose?

The site of these hundreds of people is the enterprise application project implementation team, and the excavator is Spring.

The Spring framework provides comprehensive infrastructure support for developing Java applications. Spring includes some nice features, such as dependency injection and out-of-the-box modules:

Spring JDBC

Spring MVC

Spring Security

Spring AOP

Spring ORM

Spring Test

These modules can greatly shorten the application development time and improve our work efficiency.

If you do n’t know Spring, then the interviewer of the big factory wo n’t understand why you dare to interview?

 

Spring bean life cycle

But now many programmers' understanding of Spring is only at a very shallow level. Many people only focus on the logic of the part of the code they use, and do not really understand the framework.

If you do n’t know Spring, then the interviewer of the big factory wo n’t understand why you dare to interview?

The following are common spring interview questions:

1. What is the Spring framework? What are the main modules of the Spring framework?

The Spring Framework is a Java platform that provides comprehensive and extensive basic support for the development of Java applications.

Spring helps developers solve basic problems in development, allowing developers to focus on application development.

The Spring framework itself is also carefully built according to the design pattern, which allows us to integrate the Spring framework with ease in the development environment

Frame, do n’t worry about how Spring works in the background.

The Spring framework has integrated more than 20 modules so far. These modules are mainly divided into core containers, data access / sets as shown in the figure below

Cheng, Web, AOP (Aspect-Oriented Programming), tools, messages and test modules.

2. What are the benefits of using the Spring framework?

Here are some key benefits of using the Spring framework:

 The Dependency Injection (DI) method makes the dependencies in the constructor and JavaBean properties file clear. Compared with EJB containers, IoC containers tend to be more lightweight. In this way, IoC container development and release of applications with limited memory and CPU resources becomes very beneficial. Spring does not make cars behind closed doors. Spring uses existing technologies such as ORM framework, logging framework, J2EE, Quartz and JDK Timer, and other view technologies.

 The Spring framework is organized in the form of modules. You can see the module to which it belongs by the package and class numbers. Developers only need to select the modules they need. Testing an application developed with Spring is very simple, because the test-related environment code is already included in the framework. Even simpler, using the POJO class in the form of JavaBean, you can easily use dependency injection to write test data.

 Spring's Web framework is also a well-designed Web MVC framework, which provides developers with a powerful option in choosing a web framework in addition to mainstream frameworks such as Struts, over-designed, and unpopular web frameworks.

 Spring provides a convenient transaction management interface, suitable for small local transaction processing (such as in a single DB environment) and complex common transaction processing (such as a complex DB environment using JTA).

3. Please explain the IoC in the Spring framework?

The org. Spr ingfr amework. Beans package and org. Spr ingframework. Context package in Spring form the basis of the Spring framework IoC container.

The BeanFactory interface provides an advanced configuration mechanism that makes the configuration of any type of object possible.

The ApplicationContex interface extends the BeanFactory (a sub-interface), adding other functions to the BeanFactory, such as easier integration with Spring's AOP, and also provides a mechanism to handle message resources (for internationalization), event propagation And the special configuration of the application layer, such as WebApplicationContext for Web applications.

org. springf ramework. beans. factory. BeanFac tory is a concrete implementation of Spring IoC container, used to package and manage the various beans mentioned above. The BeanFactory interface is the core interface of the SpringIoC container.

IOC: The creation, initialization, and destruction of objects are left to spring to manage, rather than being controlled by the developer, to achieve control reversal.

4. What is the difference between BeanFactory and ApplicationContext?

BeanFactory can be understood as a factory class that contains a collection of beans. The BeanFactory contains the definition of the bean, so that when the client request is received, the corresponding bean is instantiated.

BeanFactory can also generate relationships between collaboration classes when instantiating objects. This liberates the configuration of the bean itself and the bean client. BeanFactory also includes control of the bean life cycle, calling the client's initialization methods (initialization methods) and destruction methods (destruction methods).

On the surface, the application context, like the bean factory, has the definition of the bean and the setting of the relationship of the bean, and the function of distributing the bean according to the request. But applicationcontext also provides other functions on this basis.

1. Provide text messages that support internationalization.

2. System--resource file reading method

3. The event of the bean registered in the listener

The following are three more common ApplicationContext implementation methods:

1. ClassPathXmlApplicationContext: Read the context from the XML configuration file of the classpath and generate the context definition. Application, context from program environment variables

ApplicationContext context = new

ClassPathXmlAppl icat ionContext(“bean. xml”);

2. FileSystemXmlApplicationContext: The context is read by the XML configuration file in the file system.

Appl icationContext context = new

FileSys temXmlApplicationContext(“bean. xml" );

3. XmIWebApplicationContext: read the context from the XML file of the Web application.

4.AnnotationConfigApplicationContext (start container based on Java configuration)

 

If you do n’t know Spring, then the interviewer of the big factory wo n’t understand why you dare to interview?

 

5. How to use tSpring with XML?

In the Spring framework, dependencies and services need to be implemented in a special configuration file, which is a configuration file in XML format that I usually use. The format of these configuration files usually starts with <beans> and then consists of a series of bean definitions and special application configuration options.

The main purpose of SpringXML configuration is to enable all Spring components to be configured in the form of xmI files. This means that there will be no other Spring configuration types (such as declarative or Java Class-based configuration). Spring's XML configuration is implemented using a series of XML tags supported by the Spring namespace. Spring has the following main namespaces: context, beans. Jdbc, tx, aop, mvc, and aso.

Such as:

<beans>

<!-- JSON Support -- ->

<bean name="viewResolver"

class=

' org. spri ngframework. web. servlet. vi ew. BeanNameVi ewResolver"/>

<bean name=" jsonTemplate"

class=" org.

spr ingframework. web. servlet. view. json. MappingJackson2JsonV

iew' '/>

<bean id=' restTemplate"

class=" org. spr ingframework. web. client. RestTemplate' '/>

</beans>

The following web.xml is only configured with DispatcherServlet, this simplest configuration can meet the application configuration operation

Requirements for runtime components.

<web- rapp>

<display- rname>Archetype Created Web Appl icat ion</display- rname>

<servlet>

<servlet-name>spring</ servlet-name>

<servlet-

class>org. spr ingframework. web. servlet. Di spatcherServlet</servlet-

class>

<load-on-s tartup>1</load-on-startup>

</servlet>

<servlet- mapping>

<servlet- -name>spr ing</servlet -name>

<ur1-pattern>/</url-pat tern>

</servlet- mapping>

</web-app>

Due to space limitations, there is no way to show the complete spring interview questions of the editor, so the editor compiled these interview questions into a spring interview topic document, which is free to share here. Friends in need can like comments and add editors. Signal: AAAMAXIAOXIN to get it, in addition to the editor's hand, there are Spring source learning videos, interview materials for major factories in various topics, and Java core knowledge points organized by senior architects. Welcome to receive them!

 

spring interview questions and answers

 

If you do n’t know Spring, then the interviewer of the big factory wo n’t understand why you dare to interview?

 

Spring source learning video

If you do n’t know Spring, then the interviewer of the big factory wo n’t understand why you dare to interview?

 

Interview data collected from other large factories

 

If you do n’t know Spring, then the interviewer of the big factory wo n’t understand why you dare to interview?

Interview answer

 

If you do n’t know Spring, then the interviewer of the big factory wo n’t understand why you dare to interview?

Interview answer

And Java core knowledge points organized by senior architects

The knowledge points that the interviewer must ask during the interview include a lot of knowledge points, including basic knowledge, Java collection, JVM, multi-threaded concurrency, spring principle, microservices, Netty and RPC, Kafka, diary, design pattern, Java Algorithms, databases, Zookeeper, distributed cache, data structures, etc.

If you do n’t know Spring, then the interviewer of the big factory wo n’t understand why you dare to interview?

Published 238 original articles · Like 68 · Visits 30,000+

Guess you like

Origin blog.csdn.net/qq_45401061/article/details/105079014