The Spring framework makes J2EE (Java 2 Platform Enterprise Edition) development easier and is used to create testable, high performing, reusable code. Spring is commonly applied in the information technologies and financial sector due to its modularity and dependency injection features.
Spring框架使J2EE(Java 2平台企业版)的开发更加容易,并用于创建可测试的,高性能的,可重用的代码。 由于其模块化和依赖注入特性,Spring通常应用于信息技术和金融领域。
Financial technology is an exciting and evolving field for developers who want to work at companies like MIT, Accenture, or Visa, which prefer Spring over Java EE. These companies are looking for developers like you with Spring Framework experience to help digitize their enterprise needs.
对于希望在MIT,Accenture或Visa等公司工作的开发人员来说,金融技术是一个令人兴奋且不断发展的领域,他们更喜欢Spring而不是Java EE。 这些公司正在寻找像您一样具有Spring Framework经验的开发人员来帮助数字化他们的企业需求。
But, how do you know if you’re ready for an interview? And how do you prepare?
但是,您如何知道是否准备好面试呢? 你准备如何?
Today, we’ll go through a study guide of the top 40 Spring interview questions to make sure you’re ready to ace your Spring Framework interview.
今天,我们将阅读有关40个Spring面试问题的学习指南,以确保您准备好应对Spring Framework面试。
Here’s what we’ll cover today:
这是我们今天要介绍的内容:
- What is the Spring Framework? 什么是Spring框架?
- What to expect from a Spring Framework interview Spring框架访谈会带来什么
- Top 40 Questions for Spring Framework Spring框架的前40个问题
- Wrapping up and what to learn next 总结以及接下来要学习的内容

什么是Spring框架? (What Is the Spring Framework?)
The Spring Framework is an open-source application framework and Inversion of Control container written in Java. It is designed to simplify application design by automatically handling low-level functionalities. This allows developers to focus on business logic. Spring is also very adaptable with many extension modules that grow the framework’s capabilities.
Spring Framework是一个开放源代码应用程序框架,并且是用Java编写的Inversion of Control容器。 它旨在通过自动处理底层功能来简化应用程序设计。 这使开发人员可以专注于业务逻辑。 Spring还具有许多可扩展框架功能的扩展模块,因此非常适应。
While Spring doesn’t impose a specific programming model, it has gained wide popularity in the Java community as an addition to the Enterprise JavaBeans model (EJB). This is in part due to Spring’s unique selection of functionalities like inversion of control and aspect-oriented programming (AOP) that are great for working with beans.
尽管Spring没有强加特定的编程模型,但它作为Java Java Enterprise Models模型(EJB)的补充在Java社区中获得了广泛的普及。 这部分是由于Spring独特的功能选择,例如控制反转和面向方面的编程(AOP) ,这些功能非常适合使用bean。
The framework is especially suited for enterprise and financial applications due to its speed, security, and easy-to-build transaction systems. The Spring framework offers many advantages over Java EE or other Java-based frameworks, such as:
该框架因其速度,安全性和易于构建的交易系统而特别适合企业和金融应用程序。 与Java EE或其他基于Java的框架相比,Spring框架具有许多优势,例如:
Spring enables you to develop enterprise-level apps with POJOs, so you don’t need another EJB container product.
Spring使您能够使用POJO开发企业级应用程序,因此您不需要其他EJB容器产品。
Spring offers a consistent, scalable transaction management interface for both local transactions and global transactions.
Spring为本地事务和全局事务提供了一致的,可伸缩的事务管理界面 。
- Spring is organized in a modular fashion. Its web framework is a lightweight, web MVC framework. Spring以模块化的方式组织。 它的Web框架是一个轻量级的Web MVC框架。
- Spring makes innovative uses of pre-existing technologies, such as ORM frameworks, JEE, and JDK timers. Spring充分利用了现有技术,例如ORM框架,JEE和JDK计时器。
- It is easy to test an application in Spring. 在Spring中测试应用程序很容易。
- Spring provides an excellent API, so it’s easy to work with technology-specific exceptions. Spring提供了出色的API,因此可以轻松处理特定于技术的异常。
从Spring框架访谈中可以期待什么 (What to Expect From a Spring Framework Interview)
Most companies looking for Spring Framework expertise are finance companies like banks and investment firms. Some of the top employers of Spring applicants are Citibank, eBay, Visa, and J.P. Morgan.
寻求Spring Framework专业知识的大多数公司都是金融公司,例如银行和投资公司。 Spring申请人的一些顶级雇主包括花旗银行,eBay,Visa和JP Morgan。
These companies are interested in using Spring to secure and optimize their accounting and sales stack. Most interview questions will, therefore, test your knowledge of these features like dependency injection, aspect-oriented programming, and MVC.
这些公司对使用Spring来保护和优化其会计和销售堆栈感兴趣。 因此,大多数面试问题将测试您对这些功能的知识,例如依赖项注入,面向方面的编程和MVC 。
There will also be general questions to ensure you have a full understanding of each part of Spring, like naming the modules used in web application development or database connectivity.
还有一些一般性问题,以确保您完全了解Spring的各个部分,例如命名Web应用程序开发或数据库连接中使用的模块。
Finally, you’ll certainly be asked overarching questions about why Spring is used and what benefits it offers. To help you prepare, we’ve collected 40 top interview questions to refresh your knowledge on each of these categories.
最后,您肯定会被问到关于为什么使用Spring及其带来的好处的总体问题。 为了帮助您做好准备,我们收集了40个面试重点问题,以使您对这些类别的知识有所了解。
Let’s get started!
让我们开始吧!
Spring框架的前40个问题: (Top 40 Questions for Spring Framework:)
1. Spring有什么好处? (1. What are the benefits of Spring?)
Lightweight: Spring is lightweight in resource use, with the basic Spring Framework only costing 2MB of storage.
轻量级: Spring在资源使用方面是轻量级的,基本的Spring Framework仅消耗2MB的存储空间。
Scalable: Spring’s transaction management interface can scale to either a local transaction on a single database to global transactions using the JTA module
可扩展: Spring的事务管理界面可以扩展为使用JTA模块将单个数据库上的本地事务扩展为全局事务
Exception Handling: Exception handling is easy thanks to plentiful API resources for handling exceptions in each module.
异常处理:得益于用于处理每个模块中异常的大量API资源,异常处理非常容易。
Layered Architecture: Allows you to use the parts of the program you need and discard the rest.
分层体系结构:允许您使用程序中需要的部分,并丢弃其余部分。
POJO Enabled: Plain Old Java Object Programming allows you continuous testability and integration.
启用POJO:普通的Java对象编程允许您进行持续的可测试性和集成。
Open-source: Free for everyone and has no vendor lock-in.
开源:所有人免费,没有供应商锁定。
Inversion of control (IOC): Achieves loose coupling via IOC by allowing objects to give their dependencies to other objects rather without dependent objects.
控制反转(IOC):通过允许对象将其依存关系提供给其他对象,而无需依赖对象,从而通过IOC实现松散耦合。
Aspect oriented (AOP): Spring supports Aspect-oriented programming, a paradigm that separates application business logic from system services.
面向方面(AOP): Spring支持面向方面的编程,这是一种将应用程序业务逻辑与系统服务分开的范例。
2. Spring的配置文件是什么? (2. What is the configuration file for Spring?)
The configuration file for Spring is an XML
file that contains the class information for a project. They describe the configuration of each class, how they’re introduced to other classes, and dependencies across the program.
Spring的配置文件是一个XML
文件,其中包含项目的类信息。 它们描述了每个类的配置,如何将它们引入其他类以及整个程序的依赖关系。
3. Spring框架有哪些不同的模块? (3. What are the different modules of Spring Framework?)
There are around 20 modules in total and are divided into the layers of Core Container, Data Access/Integration, Web, AOP (Aspect Oriented Programming), Instrumentation, and Test.
总共大约有20个模块,分为核心容器,数据访问/集成,Web,AOP(面向方面的编程),检测和测试等层。
Core Container: The core of the Spring Framework contains four modules.
核心容器: Spring框架的核心包含四个模块。
- Spring Core 弹簧芯
- Spring Bean Spring Bean
- SpEL (Spring Expression Language) SpEL(Spring表达语言)
- Spring Context Spring语境
Data Access/Integration: Supports database interactions with five modules.
数据访问/集成:支持与五个模块的数据库交互。
- JDBC (Java DataBase Connectivity) JDBC(Java数据库连接)
- ORM (Object Relational Mapping) ORM(对象关系映射)
- OXM (Object XML Mappers) OXM(对象XML映射器)
- JMS (Java Messaging Service) JMS(Java消息服务)
- Transaction 交易
Web: Adds support for creating a web application using 4 modules.
Web:添加了对使用4个模块创建Web应用程序的支持。
- Web 网页
- Web — MVC Web — MVC
- Web — Socket Web —插座
- Web — Portlet Web — Portlet
Aspect-Oriented Programming: This layer allows you to decouple code using Advice and Pointcut functions.
面向方面的编程:通过这一层,您可以使用建议和切入点功能解耦代码。
Instrumentation: This layer adds support for class instrumentation and classloader implementations.
工具:这一层增加了对类工具和类加载器实现的支持。
Test: Adds support for testing using Junit and TestNG.
测试:增加了对使用Junit和TestNG进行测试的支持。
Miscellaneous: Two modules exist outside of these layer categories.
杂项:这些层类别之外还存在两个模块。
Aspects: Allows Spring to integrate with Aspect.
Aspects:允许Spring与Aspect集成。
Messaging: Adds support for STOMP, an annotation programming model, and allows you to route STOMP messages from WebSocket clients.
消息传递:添加对STOMP(注释编程模型)的支持,并允许您从WebSocket客户端路由STOMP消息。
4. Spring应用程序有哪些不同的组件? (4. What are the different components of a Spring application?)
Spring applications contain five components:
Spring应用程序包含五个组件:
Interface: Defines program functions.
界面:定义程序功能。
Bean class: Contains properties, setter and getter methods for accessing the bean, and specific functions, etc.
Bean类:包含属性,用于访问Bean的setter和getter方法以及特定的函数等。
Spring Aspect-Oriented Programming (AOP): Includes cross-cutting concerns functionality, which is not supported in Object-Oriented Programming.
Spring面向方面的编程(AOP):包括横切关注点功能,面向对象的编程中不支持。
Bean Configuration File: Contains the information of classes, how to configure them, and defines their relationships.
Bean配置文件:包含类的信息,如何配置它们以及定义它们之间的关系。
User program: Calls functions across the program
用户程序:在整个程序中调用函数
5.什么是依赖注入? (5. What is dependency injection?)
Dependency injection (DI) is a concept that defines how multiple classes should be connected. This is one example of Inversion of Control. You don’t need to connect services and components explicitly in code when using dependency injection. Instead, you describe the services needed by each component in an XML
configuration file and allow the IOC container to connect them automatically.
依赖注入(DI)是定义如何连接多个类的概念。 这是控制反转的一个例子。 使用依赖注入时,无需在代码中显式连接服务和组件。 相反,您在XML
配置文件中描述每个组件所需的服务,并允许IOC容器自动连接它们。

6.什么是Spring IoC容器? (6. What is a Spring IoC container?)
An IoC container creates, configures, and connects objects while also managing their lifecycle. The container gets instructions on these areas from configuration metadata given by the user.
IoC容器创建,配置和连接对象,同时还管理对象的生命周期。 容器从用户给定的配置元数据中获取有关这些区域的指令。
7. IoC的类型是什么? (7. What are the types of IoC?)
BeanFactory Container: This factory class contains a prepackaged collection of beans that instantiate when called by clients. This is the most basic container to support DI.
BeanFactory容器:此工厂类包含预包装的bean集合,这些bean在被客户端调用时实例化。 这是支持DI的最基本的容器。
ApplicationContext Container: Built on top of the BeanFactory Container, this container provides additional enterprise-focused functionalities. For example, ApplicationContext containers grant the ability to resolve textual messages and publish application events.
ApplicationContext容器:在BeanFactory容器之上构建,此容器提供了其他针对企业的功能。 例如,ApplicationContext容器授予解析文本消息和发布应用程序事件的功能。
8.什么是面向方面的编程(AOP)? (8. What is Aspect-Oriented Programming (AOP)?)
AOP is a programming technique that allows programmers to modularize behavior that is used across the typical divisions of responsibility found in Object-Oriented Programming. The core AOP construct of aspects are behaviors applicable across classes. Extracting these behaviors from individual beans to aspects allows them to be reused easily.
AOP是一种编程技术,允许程序员对行为进行模块化,该行为用于面向对象编程中的典型职责划分。 问题的核心AOP结构是适用于整个类的行为。 从各个bean的各个方面提取这些行为,可以轻松地重用它们。
9.什么是Spring Bean? (9. What are Spring beans?)
Beans are objects created from configuration metadata when it is passed to the IOC container. They form the foundation of all Spring programs. The IOC container instantiates, configures, connects, and manages each bean.
Bean是在传递给IOC容器时从配置元数据创建的对象。 它们构成了所有Spring程序的基础。 IOC容器实例化,配置,连接和管理每个bean。
10. ApplicationContext的常见实现是什么? (10. What are the common implementations of the ApplicationContext?)
Three of the most popular containers are:
三种最受欢迎的容器是:
FileSystemXmlApplicationContext: Causes the constructor to load bean definitions from an XML configuration file. Must be pointed to with a full file path.
FileSystemXmlApplicationContext:使构造函数从XML配置文件加载Bean定义。 必须使用完整的文件路径指向。
ClassPathXmlApplicationContext: This container does the same as the above but does not require a full file path. Instead, you set the
CLASSPATH
property and allow the container to find theXML
at thatCLASSPATH
.ClassPathXmlApplicationContext:此容器与以上操作相同,但不需要完整的文件路径。 相反,您可以设置
CLASSPATH
属性,并允许容器在该CLASSPATH
上找到XML
。WebXmlApplicationContext: Loads all bean definitions to a web application from an
XML
file.WebXmlApplicationContext:将所有bean定义从
XML
文件加载到Web应用程序。
11. BeanFactory和ApplicationContext有什么区别? (11. What is the difference between BeanFactory and ApplicationContext?)
The BeanFactory is a basic, space-efficient container with limited functionality. It is best used for simple tasks or when using low-resource machines.
BeanFactory是一个基本的,节省空间的容器,功能有限。 它最适合用于简单任务或使用资源不足的计算机。
The ApplicationContext is an advanced, more intensive container with an extended interface and additional capabilities like AOP. This container is best used when you need more functionality than the BeanFactory and have ample resources available on the machine.
ApplicationContext是具有扩展接口和高级功能(如AOP)的高级,密集型容器。 当您需要比BeanFactory更多的功能并且机器上有足够的资源时,最好使用此容器。
12.如何在Spring应用程序中添加bean? (12. How do you add a bean in a Spring application?)
We must annotate a method: @Bean
annotation. When JavaConfig encounters this method, it will execute that method and register the return value as a bean within a BeanFactory.
我们必须注释一个方法: @Bean
注释。 当JavaConfig遇到此方法时,它将执行该方法并将返回值注册为BeanFactory中的Bean。
package io.educative;
public class User {
private String name;
private String address;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
13. Spring支持哪些bean作用域? (13. What bean scopes does Spring support?)
Spring supports five scopes for beans:
Spring支持bean的五个作用域:
Singleton: Scopes a bean definition to be restricted to a single instance per Spring IoC container
Singleton:将bean定义的范围限制为每个Spring IoC容器一个实例
Prototype: Scopes a single bean to enable any number of instances.
原型:作用域单个bean以启用任意数量的实例。
Request: Scopes a bean definition to a single HTTP request within an ApplicationContext
请求:将bean定义的作用域限定为ApplicationContext中的单个HTTP请求
Session: Scopes a bean definition to an HTTP session within an ApplicationContext
会话:将bean定义的作用域限定为ApplicationContext中的HTTP会话
Global-session: Scopes a bean definition to a Global HTTP
全局会话:将bean定义的作用域限定为全局HTTP
14. Bean生命周期的步骤是什么? (14. What are the steps of the Bean lifecycle?)

There are seven steps to the Bean lifecycle:
Bean生命周期有七个步骤:
Instantiate: The bean is instantiated by the Spring container using the bean’s definition found in the
XML
configuration file.实例化: Bean由Spring容器使用
XML
配置文件中的Bean定义实例化。Populate properties: Spring populates all the defined properties from the
XML
file using dependency injection.填充属性: Spring使用依赖项注入从
XML
文件填充所有定义的属性。Set Bean Name: Spring passes the bean’s identifier to the
setBeanName()
method if the bean uses theBeanNameAware
interface.设置Bean名称:如果Bean使用
BeanNameAware
接口,则Spring将其标识符传递给setBeanName()
方法。Set Bean factory: Spring passes the
beanfactory
to thesetBeanFactory()
method if the bean is configured to use theBeanFactoryAware
interface.设置Bean工厂:如果将Bean配置为使用
BeanFactoryAware
接口,则Spring将beanfactory
传递给setBeanFactory()
方法。Pre Initialization: Spring calls any
BeanPostProcessors
associated with the bean using thepostProcessorBeforeInitialization()
method.预初始化: Spring使用
postProcessorBeforeInitialization()
方法调用与该Bean相关联的任何BeanPostProcessors
。Initialization: The bean is then initialized. Any special initialization process specified in the
init-method
is followed.初始化:然后将Bean初始化。 遵循
init-method
中指定的任何特殊初始化过程。Post Initialization: All defined
postProcessAfterInitialization()
methods are called. Now the bean is complete. Beans that implementDisposableBean
will be deleted using thedestroy()
after their job is finished.初始化后:调用所有定义的
postProcessAfterInitialization()
方法。 现在,bean完成了。 实现DisposableBean
Bean在其工作完成后将使用destroy()
删除。
15.在Spring解释内豆 (15. Explain inner beans in Spring)
An inner bean is used as a property of another bean. Inner beans can be defined in the configuration XML
file under either the <property>
or <constructor-arg>
elements. All inner beans are always scoped as prototype
and don’t have identifiers.
内部bean用作另一个bean的属性。 可以在配置XML
文件中的<property>
或<constructor-arg>
元素下定义内部bean。 所有内部bean始终以prototype
为范围,并且没有标识符。
16.什么是bean自动接线? (16. What is bean auto wiring?)
This is a Spring capability that allows the Spring container to automatically set dependency relationships between collaborating beans by looking at the BeanFactory. Auto wiring can be set to define these relationships using the beans’ names or type or even class constructors.
这是一种Spring功能,它允许Spring容器通过查看BeanFactory来自动设置协作bean之间的依赖关系。 可以设置自动装配以使用bean的名称或类型甚至类构造函数来定义这些关系。
17.如何在Spring中注入Java Collection? (17. How can you inject a Java Collection in Spring?)
Java collections can be injected in four different ways:
Java集合可以通过四种不同的方式注入:
<list>
: Helps you wire sets of values like lists while allowing duplicates.<list>
:帮助您连接一组值,如列表,同时允许重复。<set>
: Helps you wire a set of values while avoiding duplicates.<set>
:帮助您连接一组值,同时避免重复。<map>
: Allows you to inject a collection of key-value pairs of any data type.<map>
:允许您注入任何数据类型的键值对的集合。<props>
: Allows you to inject a collection of key-value pairs with both keys and values of typeString
.<props>
:允许您注入具有键和String
类型值的键/值对集合。
18.什么是联接点? (18. What is a Joinpoint?)
Joinpoints represent any point in a program where an action is taken. Examples of a joinpoint include when handling an exception or a method is executed. When using AOP, only method executions are joinpoints.
连接点代表程序中执行操作的任何点。 连接点的示例包括在处理异常或执行方法时。 使用AOP时,仅方法执行是连接点。
19.Spring的建议是什么? (19. What is an Advice in Spring?)
An Advice is the action taken at a given joinpoint. AOP uses an Advice as an interceptor before the method’s execution is complete.
建议是在给定的连接点处执行的操作。 在方法执行完成之前,AOP使用Advice作为拦截器。
20. Spring框架的建议类型是什么? (20. What are the types of advice for a Spring Framework?)
Before: These are advices that execute before the joinpoint methods. They’re marked using the
@Before
annotation mark.之前:这些是在连接点方法之前执行的建议。 它们使用
@Before
注释标记进行标记。After returning: These execute after the joinpoint’s method completes executing without issue. They’re marked using the
@AfterReturning
annotation mark.返回之后:它们在联接点的方法完成执行而没有问题之后执行。 它们使用
@AfterReturning
注释标记进行标记。After throwing: These execute only if the joinpoint method ends by throwing an exception. They’re marked using the
@AfterThrowing
annotation mark.抛出后:仅当joinpoint方法以抛出异常结束时执行。 它们使用
@AfterThrowing
注释标记进行标记。After: These execute after a joinpoint method, regardless of how it completes. They’re marked using the
@After
annotation mark.之后:它们在联接点方法之后执行,无论它如何完成。 它们使用
@After
注释标记进行标记。Around: These execute before and after a joinpoint and are marked using the
@Around
annotation mark.围绕:它们在连接点之前和之后执行,并使用
@Around
注释标记进行标记。
21.什么是编织? (21. What is Weaving?)
Weaving in Spring is the process of linking elements to other application types or objects to create advised objects. This is done at runtime.
在Spring中进行编织是将元素链接到其他应用程序类型或对象以创建建议对象的过程。 这是在运行时完成的。
22.描述Spring DAO支持 (22. Describe Spring DAO support)
Data Access Object (DAO) support is a set of tools that make it easier to work with data access technologies like Hibernate and JDO with improved consistency. It also catches technology-specific errors automatically. Together these make DAOs easier to work with and allows you to switch between persistence technologies without error.
数据访问对象(DAO)支持是一组工具,使使用Hibernate和JDO之类的数据访问技术更加容易并具有更高的一致性。 它还会自动捕获特定于技术的错误。 这些都使DAO易于使用,并允许您在持久性技术之间切换而不会出错。
23.什么是JDBC? Spring JDBC API中存在哪些类? (23. What is the JDBC? Which classes are present in the Spring JDBC API?)
JDBC stands for Java Database Connectivity. It is an application programming interface in Java used to define how a program may access a database. The JDBC API contains:
JDBC代表Java数据库连接。 它是Java中的应用程序编程接口,用于定义程序如何访问数据库。 JDBC API包含:
JdbcTemplate
JdbcTemplate
NamedParameterJdbcTemplate
NamedParameterJdbcTemplate
SimpleJdbcCall
SimpleJdbcCall
SimpleJdbcInsert
SimpleJdbcInsert
SimpleJdbcTemplate
SimpleJdbcTemplate
24.什么是Spring Model-View-Controller(MVC)框架? (24. What is the Spring Model-View-Controller (MVC) framework?)
The Spring MVC framework provides model-view-controller architecture and pre-made components used to develop loosely coupled web applications. Using MVC, you can separate different aspects of the program like a business, input, and UI logics while still having a loose coupling between each. This allows for greater flexibility in your web applications.
Spring MVC框架提供了模型视图控制器架构和用于开发松耦合Web应用程序的预制组件。 使用MVC,您可以分离程序的不同方面,例如业务,输入和UI逻辑,同时彼此之间仍然保持松散耦合。 这使您的Web应用程序具有更大的灵活性。

25. Spring MVC框架有哪些部分? (25. What are the parts of Spring MVC framework?)
The three main parts of MVC are:
MVC的三个主要部分是:
DispatcherServlet: This part of MVC manages all the HTTP requests and responses that interact with the program. The
DispatcherServlet
first receives relevant handler mapping from the configuration file and then passes off the request to the controller. TheDispatcherServlet
is the most important part of the Spring Web MVC framework.DispatcherServlet: MVC的这一部分管理与程序交互的所有HTTP请求和响应。
DispatcherServlet
首先从配置文件接收相关的处理程序映射,然后将请求传递给控制器。DispatcherServlet
是Spring Web MVC框架中最重要的部分。WebApplicationContext: This acts as an extension of the plain ApplicationContext with extra features necessary for web applications. It can uniquely resolve themes and automatically decide which servlet it is associated with.
WebApplicationContext:这是普通ApplicationContext的扩展,具有Web应用程序所需的额外功能。 它可以唯一地解析主题,并自动确定与之关联的servlet。
Controllers: These are beans within the
DispatcherServlet
that act as filters between user input and application response. Controllers take user input, decide if it should be transformed into either a View or a Model, and finally returns the transformed input to the View Resolver for review.控制器:这些是
DispatcherServlet
中的bean,用作用户输入和应用程序响应之间的过滤器。 控制器接受用户输入,决定是否应该将其转换为View或Model,最后将转换后的输入返回给View Resolver进行审查。
26. DispatcherServlet的不同部分是什么? (26. What are the different parts of the DispatcherServlet?)
Handler Mapping: An interface that defines the mapping between handler and request objects. Can be used to create a custom mapping strategy.
处理程序映射:定义处理程序和请求对象之间的映射的接口。 可用于创建自定义映射策略。
Controller: Determines the app’s response to user input by sorting input requests by their desired outcome. Input is either immediately returned with a View or is transformed into a Model before being passed to the view-resolver.
控制器:通过按输入请求的期望结果对它们进行排序,确定应用对用户输入的响应。 输入可以立即通过View返回,也可以在传递给View-Resolver之前转换为Model。
View-Resolver: Takes and renders Models from the controller by mapping between View names and actual Views.
View-Resolver:通过在视图名称和实际视图之间进行映射,从控制器获取并渲染模型。
27.如何在Spring中打开注释布线? (27. How can annotation wiring be turned on in Spring?)
To allow annotation wiring, include <context:annotation-config/>
in your XML
configuration file:
要允许注释连接,请在XML
配置文件中包含<context:annotation-config/>
:
<beans
//...
xmlns:context="http://www.springframework.org/schema/context"
//...
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
//...
<context:annotation-config /> //annotation wiring enabled here
//...
</beans>
28.什么是Spring Boot? (28. What is the Spring Boot?)
Spring Boot is an open-source Java framework used to create microservices. It is a project built on top of Spring to simplify the task of deploying Java applications. Its two major components are the Spring Framework and Embedded HTTP Servers. Spring Boot is used to:
Spring Boot是用于创建微服务的开源Java框架。 这是一个基于Spring的项目,旨在简化Java应用程序的部署任务。 它的两个主要组件是Spring框架和嵌入式HTTP服务器。 Spring Boot用于:
- Simplify the process of developing production-ready Spring applications 简化开发就绪的Spring应用程序的开发过程
Avoid
XML
configuration in Spring避免在Spring中进行
XML
配置- Reduce development time by decreasing the number of needed import statements 通过减少所需的导入语句的数量来减少开发时间
- Provide an opinionated development approach 提供周到的开发方法
These are often used to get Spring applications running quickly.
这些通常用于使Spring应用程序快速运行。

29.什么是React式编程? (29. What is Reactive Programming?)
Reactive Programming is a programming paradigm that relies on programmed actions trigger on events rather than based on the chronological order of the code. Reactive programs make efficient use of computer resources and scale well with just a few threads. Its non-sequential form allows you to avoid stack blocking and maintain responsiveness.
响应式编程是一种编程范例,它依赖于在事件上触发的已编程动作,而不是基于代码的时间顺序。 响应式程序可以有效利用计算机资源,并且只需几个线程即可很好地扩展。 它的非顺序形式使您可以避免堆栈阻塞并保持响应速度。

30.什么是Spring Webflux? (30. What is Spring Webflux?)
Webflux is a reactive web framework that serves as an alternative to MVC. Webflux provides better scalability and prevents stack blocking.
Webflux是一种React式Web框架,可以替代MVC。 Webflux提供了更好的可伸缩性并防止了堆栈阻塞。

31. WebClient和Webtestclient有什么区别? (31. What is the difference between the WebClient and Webtestclient?)
The WebClient
is a component from the Web Reactive framework that makes it easier to build reactive and non-blocking web applications.
WebClient
是Web Reactive框架中的一个组件,使构建响应式和非阻塞式Web应用程序更加容易。
The Webtestclient
is a version of this client with all the same features but is disconnected from live environments. The test client doesn’t need an HTTP server live environment to work, making it a good test environment for new applications. It can connect to any server over an HTTP connection or sync directly with WebFlux to apply mock HTTP requests and generate response objects.
Webtestclient
是此客户端的一个版本,具有所有相同的功能,但已与实时环境断开连接。 测试客户端不需要HTTP服务器实时环境即可工作,这使其成为新应用程序的良好测试环境。 它可以通过HTTP连接连接到任何服务器,也可以直接与WebFlux同步以应用模拟HTTP请求并生成响应对象。
32. Spring Boot可以在同一应用程序中允许Spring MVC或Spring WebFlux吗? (32. Can Spring Boot allow Spring MVC or Spring WebFlux in the same application?)
Boot allows both in the same application but can only apply one at a time. WebFlux is a non-blocking framework while MVC is a blocking framework, making them incompatible together.
引导允许两个应用程序都在同一应用程序中,但一次只能应用一个。 WebFlux是一个非阻塞框架,而MVC是一个阻塞框架,使它们无法兼容。
33. Spring 5可以与Jdk9模块化集成吗? (33. Can Spring 5 Integrate with the Jdk9 Modularity?)
Yes, Spring 5 can integrate with Jdk9. Here’s how you can do it:
是的,Spring 5可以与Jdk9集成。 方法如下:
Create a new class
创建一个新的班级
package com.hello;
public class HelloWorld {
public String sayHello(){
return "HelloWorld";
}
}
Create a new module
创建一个新模块
module com.hello {
export com.hello;
}
Create a new Java Project
创建一个新的Java项目
module com.hello.client {
requires com.hello;
}
Test the new module
测试新模块
public class HelloWorldClient {
public static void main(String[] args){
HelloWorld helloWorld = new HelloWorld();
log.info(helloWorld.sayHello());
}
}
34. Spring中的代理是什么? (34. What is a Proxy in Spring?)
A Proxy is an object created after applying advice to a target object. Proxies are used to perform meta-programming operations like intercepting an object call or altering an object’s property.
代理是在将建议应用于目标对象之后创建的对象。 代理用于执行元编程操作,例如拦截对象调用或更改对象的属性。
35.目标对象和代理对象什么时候相同? (35. When is the target object and proxy object the same?)
This is a “gotcha” question used to test if you know how different object types interact. The target and proxy objects are the same when dealing with client objects.
这是一个“陷阱”问题,用于测试您是否知道不同的对象类型如何交互。 处理客户端对象时,目标和代理对象是相同的 。
36.如何将配置元数据提供给Spring容器? (36. How can configuration metadata be provided to the Spring container?)
XML-Based Configuration: This type of configuration stores all of a program’s bean definitions and dependencies in an XML
file. These files are imported by providing a full file path, like on line 1 below.
基于XML的配置:这种类型的配置将程序的所有bean定义和依赖项存储在XML
文件中。 通过提供完整的文件路径来导入这些文件,例如下面的第1行。
<bean id="bean1" class="io.Educative.firstSpring.Bean1">
<property name="name" value="Educative"></property>
</bean>
Annotation-Based Configuration: You can instead create annotations on a class, method, or field in a bean to position it within a component class.
基于注释的配置:您可以在bean的类,方法或字段上创建注释,以将其放置在组件类中。
<beans>
<context:annotation-config/>
<!-- bean definitions go here -->
</beans>
Java-Based Configuration: This type of configuration allows you to skip <bean>
syntax and instead use the @Bean
tag to achieve the same thing. You can also create configuration classes with the @Configuration
tag, allowing you to create dependencies between beans by calling other@Bean
classes.
基于Java的配置:这种配置类型使您可以跳过<bean>
语法,而使用@Bean
标记来实现相同的目的。 您还可以使用@Configuration
标记创建配置类,从而允许您通过调用其他@Bean
类在bean之间创建依赖关系。
@Configuration
public class BeanConfig
{
@Bean
public Bean1 myBean()
{ return new Bean1(); }
}
37. Spring DAO类可能引发哪些异常? (37. What are the possible exceptions that can be thrown by Spring DAO classes?)
DataAccessResourceFailureException
DataAccessResourceFailureException
CleanUpFailureDataAccessException
CleanUpFailureDataAccessException
InvalidDataAccessApiUsageException
InvalidDataAccessApiUsageException
InvalidDataAccessResourceUsageException
InvalidDataAccessResourceUsageException
UncategorizedDataAccessException
UncategorizedDataAccessException
DataIntegrityViolationException
DataIntegrityViolationException
DeadLockLoserDatAccessException
DeadLockLoserDatAccessException
OptimisticLockingFailureEexception
OptimisticLockingFailureEexception
IncorrectUpdateSemanticsDataAccessException
IncorrectUpdateSemanticsDataAccessException
TypeMismatchDataAccessException
TypeMismatchDataAccessException
ObjectRetrievalFailureException
ObjectRetrievalFailureException
DataRetrievalFailureException
DataRetrievalFailureException
38.使用Spring可以通过什么方式访问Hibernate? (38. What are the ways Hibernate can be accessed using Spring?)
Hibernate ORM is an object-relational mapping framework for Java. It is used with Spring to map object-oriented domain models to a relational database. Hibernate can be accessed in Spring in the following two ways:
Hibernate ORM是Java的对象关系映射框架。 它与Spring一起使用,以将面向对象的域模型映射到关系数据库。 可以通过以下两种方式在Spring中访问Hibernate:
First, extend
HibernateDAOSupport
and then apply an AOP Interceptor node首先,扩展
HibernateDAOSupport
,然后应用AOP拦截器节点- Use Inversion of Control with Hibernate Template and Callback structures 将控制反转与Hibernate模板和回调结构一起使用
39.指出Spring AOP中关注点和跨领域关注点之间的区别吗? (39. Point out the difference between concern and cross-cutting concern in Spring AOP?)
A concern is the target functionality we’re trying to implement into a particular module of our application.
一个问题是我们试图在应用程序的特定模块中实现的目标功能。
A cross-cutting concern is a concern that is used across the entire application rather than just in a particular module.
横切关注点是在整个应用程序中使用的关注点,而不仅仅是在特定模块中使用。
Data logging is a good example of a cross-cutting concern as logging is useful and desired regardless of what module it is in.
数据记录是横切关注点的一个很好的例子,因为无论它位于哪个模块中,记录都是有用且需要的。
40. Spring提供哪些事务管理类型? (40. What are the types of transaction management available in Spring?)
Declarative transaction management: This type manages transactions using annotations or XML
configurations to separate transaction management from the program’s business code. While easy to maintain, this style is more restricted in its capabilities.
声明式事务管理:此类型使用注释或XML
配置管理事务,以将事务管理与程序的业务代码分开。 尽管易于维护,但这种样式的功能受到更多限制。
Programmatic transaction management: This type manages transactions with specifically made programs. The customization of these programs allows for more flexible management but introduces more room for error in the process.
程序化交易管理:此类型使用专门制作的程序来管理交易。 这些程序的自定义允许更灵活的管理,但是在过程中引入了更多的错误空间。
总结和下一步学习 (Wrapping Up and What to Learn Next)
Congratulations on completing these 40 Spring Framework interview questions. As with any interview, success in a Spring interview comes down to your preparation, practice with a variety of interview questions, experience with Spring projects, and familiarity with behavioral interview tips.
恭喜您完成了这40个Spring Framework面试问题。 与任何面试一样,Spring面试的成功取决于您的准备,进行各种面试问题的练习,Spring项目的经验以及对行为面试技巧的熟悉。
Be sure to refresh your Java knowledge before studying Spring in depth.
在深入研究Spring之前,请务必刷新您的Java知识。
Even if you don’t get an offer your first time around, the experience and exposure will help you stand out when you reapply. The most important thing is to stay confident and trust that you deserve this job! Some projects you can explore to put your Spring knowledge into practice are:
即使您第一次没有收到报价,经验和曝光也可以帮助您在重新申请时脱颖而出。 最重要的是要保持自信和信任,您应该得到这份工作! 您可以探索一些将Spring知识付诸实践的项目:
- Agile Express 敏捷快递
- Spring PetClinc SpringPetClinc
- Tudu Lists Tudu列表
- Spring Rich Client Spring富客户
- Java Small Business Platform Java小型企业平台
Happy learning!
学习愉快!
翻译自: https://medium.com/better-programming/the-top-40-questions-from-spring-boot-interviews-50660eaf74a