1. Overview
1.概述
Since its introduction, Spring Boot has been a key player in the Spring ecosystem. This project makes our life much easier with its auto-configuration ability.
自推出以来,Spring Boot一直是Spring生态系统中的一个重要角色。这个项目以其自动配置能力使我们的生活变得更加轻松。
In this tutorial, we’ll cover some of the most common questions related to Spring Boot that may come up during a job interview.
在本教程中,我们将介绍一些在求职面试中可能出现的与Spring Boot有关的最常见问题。
2. Questions
2.问题
Q1. What Is Spring Boot and What Are Its Main Features?
Q1.什么是Spring Boot,它的主要特点是什么?
Spring Boot is essentially a framework for rapid application development built on top of the Spring Framework. With its auto-configuration and embedded application server support, combined with the extensive documentation and community support it enjoys, Spring Boot is one of the most popular technologies in the Java ecosystem as of date.
Spring Boot本质上是一个建立在Spring框架之上的快速应用开发框架。凭借其自动配置和嵌入式应用服务器支持,再加上其享有的大量文档和社区支持,Spring Boot是迄今为止Java生态系统中最受欢迎的技术之一。
Here are a few salient features:
这里有几个突出的特点。
- Starters – a set of dependency descriptors to include relevant dependencies at a go
- Auto-configuration – a way to automatically configure an application based on the dependencies present on the classpath
- Actuator – to get production-ready features such as monitoring
- Security
- Logging
Q2. What Are the Differences Between Spring and Spring Boot?
Q2.Spring和Spring Boot之间的区别是什么?
The Spring Framework provides multiple features that make the development of web applications easier. These features include dependency injection, data binding, aspect-oriented programming, data access and many more.
Spring框架提供了多种功能,使网络应用程序的开发更加容易。这些功能包括依赖性注入、数据绑定、面向方面的编程、数据访问等等。
Over the years, Spring has been growing more and more complex, and the amount of configuration such application requires can be intimidating. This is where Spring Boot comes in handy — it makes configuring a Spring application a breeze.
多年来,Spring越来越复杂,这种应用所需的配置量可能让人望而生畏。这就是Spring Boot的用武之地–它使配置Spring应用程序变得轻而易举。
Essentially, while Spring is unopinionated, Spring Boot takes an opinionated view of the platform and libraries, letting us get started quickly.
从本质上讲,Spring是没有主见的,而Spring Boot对平台和库的看法是有主见的,让我们快速上手。
Here are two of the most important benefits Spring Boot brings in:
下面是Spring Boot带来的两个最重要的好处。
- Auto-configure applications based on the artifacts it finds on the classpath
- Provide non-functional features common to applications in production, such as security or health checks
Please check out our other tutorial for a detailed comparison between vanilla Spring and Spring Boot.
请查看我们的其他教程,了解vanilla Spring和Spring Boot的详细比较。
Q3. How Can We Set Up a Spring Boot Application With Maven?
Q3.我们如何用Maven设置Spring Boot应用程序?
We can include Spring Boot in a Maven project just like we would any other library. However, the best way is to inherit from the spring-boot-starter-parent project and declare dependencies to Spring Boot starters. Doing this lets our project reuse the default settings of Spring Boot.
我们可以像对待其他库一样,将Spring Boot纳入Maven项目中。然而,最好的方法是从spring-boot-starter-parent项目中继承,并声明对Spring Boot starters的依赖。这样做可以让我们的项目重新使用Spring Boot的默认设置。
Inheriting the spring-boot-starter-parent project is straightforward — we only need to specify a parent element in pom.xml:
继承spring-boot-starter-parent项目很简单 – 我们只需要在pom.xml中指定一个parent元素。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.0.RELEASE</version>
</parent>
We can find the latest version of spring-boot-starter-parent on Maven Central.
我们可以在Maven中心上找到最新版本的spring-boot-starter-parent。
Using the starter parent project is convenient but not always feasible. For instance, if our company requires all projects to inherit from a standard POM, we can still benefit from Spring Boot’s dependency management using a custom parent.
使用启动器父项目很方便,但并不总是可行的。例如,如果我们公司要求所有项目都继承自标准的POM,我们仍然可以使用custom parent,从Spring Boot的依赖管理中获益。
Q4. What Is Spring Initializr?
Q4.什么是Spring Initializr?
Spring Initializr is a convenient way to create a Spring Boot project.
Spring Initializr是创建Spring Boot项目的一种便捷方式。
We can go to the Spring Initializr site, choose a dependency management tool (either Maven or Gradle), a language (Java, Kotlin or Groovy), a packaging scheme (Jar or War), version and dependencies, and download the project.
我们可以到Spring Initializr网站,选择一个依赖管理工具(Maven或Gradle)、一种语言(Java、Kotlin或Groovy)、一种打包方案(Jar或War)、版本和依赖性,然后下载项目。
This creates a skeleton project for us and saves setup time so that we can concentrate on adding business logic.
这为我们创建了一个骨架项目,节省了设置时间,这样我们就可以专注于添加业务逻辑。
Even when we use our IDE’s (such as STS or Eclipse with STS plugin) new project wizard to create a Spring Boot project, it uses Spring Initializr under the hood.
即使我们使用IDE(如STS或带有STS插件的Eclipse)的新项目向导来创建Spring Boot项目,它也会在引擎盖下使用Spring Initializr。
Q5. What Spring Boot Starters Are Available Out There?
Q5.外面有哪些Spring Boot启动器?
Each starter plays a role as a one-stop shop for all the Spring technologies we need. Other required dependencies are then transitively pulled in and managed in a consistent way.
每个启动器都扮演着我们所需要的所有Spring技术的一站式商店的角色。然后,其他所需的依赖性被拉入并以一致的方式管理。
All starters are under the org.springframework.boot group and their names start with spring-boot-starter-. This naming pattern makes it easy to find starters, especially when working with IDEs that support searching dependencies by name.
所有启动器都在org.springframework.boot组下,其名称以spring-boot-starter-开头。这种命名模式使我们很容易找到启动器,特别是在使用支持按名称搜索依赖关系的IDE时。
At the time of this writing, there are more than 50 starters at our disposal. Here, we’ll list the most common:
在写这篇文章的时候,有50多个启动器供我们使用。在这里,我们将列出最常见的。
- spring-boot-starter: core starter, including auto-configuration support, logging and YAML
- spring-boot-starter-aop: for aspect-oriented programming with Spring AOP and AspectJ
- spring-boot-starter-data-jpa: for using Spring Data JPA with Hibernate
- spring-boot-starter-security: for using Spring Security
- spring-boot-starter-test: for testing Spring Boot applications
- spring-boot-starter-web: for building web, including RESTful, applications using Spring MVC
For a complete list of starters, please see this repository.
关于启动器的完整列表,请参见这个资源库。
To find more information about Spring Boot starters, take a look at Intro to Spring Boot Starters.
要查找有关Spring Boot启动器的更多信息,请看Intro to Spring Boot Starters。
Q6. How to Disable a Specific Auto-Configuration?
Q6.如何禁用一个特定的自动配置?
If we want to disable a specific auto-configuration, we can indicate it using the exclude attribute of the @EnableAutoConfiguration annotation.
如果我们想禁用一个特定的自动配置,我们可以使用@EnableAutoConfiguration注解的exclude属性来表示。
For instance, this code snippet neutralizes DataSourceAutoConfiguration:
例如,这个代码片段中和了DataSourceAutoConfiguration。
// other annotations
@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
public class MyConfiguration { }
If we enabled auto-configuration with the @SpringBootApplication annotation — which has @EnableAutoConfiguration as a meta-annotation — we could disable auto-configuration with an attribute of the same name:
如果我们用@SpringBootApplication注解启用自动配置–它有@EnableAutoConfiguration作为元注解–我们可以用同名的属性禁用自动配置。
// other annotations
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class MyConfiguration { }
We can also disable an auto-configuration with the spring.autoconfigure.exclude environment property. This setting in the application.properties file does the same thing as before:
我们也可以用spring.autoconfigure.exclude环境属性禁用一个自动配置。这个设置在application.properties文件中的作用与之前相同。
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
Q7. How to Register a Custom Auto-Configuration?
Q7.如何注册一个自定义的自动配置?
To register an auto-configuration class, we must have its fully qualified name listed under the EnableAutoConfiguration key in the META-INF/spring.factories file:
要注册一个自动配置类,我们必须在META-INF/spring.plants文件中的EnableAutoConfiguration键下列出其完全合格的名称。
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.baeldung.autoconfigure.CustomAutoConfiguration
If we build a project with Maven, that file should be placed in the resources/META-INF directory, which will end up in the mentioned location during the package phase.
如果我们用Maven构建项目,该文件应放在resources/META-INF目录下,在package阶段,它最终会出现在上述位置。
Q8. How to Tell an Auto-Configuration to Back Away When a Bean Exists?
Q8.如何告诉自动配置在有Bean存在时退缩?
To instruct an auto-configuration class to back off when a bean already exists, we can use the @ConditionalOnMissingBean annotation.
为了指示自动配置类在Bean已经存在的情况下退缩,我们可以使用@ConditionalOnMissingBean注解。
The most noticeable attributes of this annotation are:
这种注释最引人注目的属性是。
- value – the types of beans to be checked
- name – the names of beans to be checked
When placed on a method adorned with @Bean, the target type defaults to the method’s return type:
当放在一个装饰有@Bean的方法上时,目标类型默认为该方法的返回类型。
@Configuration
public class CustomConfiguration {
@Bean
@ConditionalOnMissingBean
public CustomService service() { ... }
}
Q9. How to Deploy Spring Boot Web Applications as Jar and War Files?
Q9.如何将Spring Boot Web应用程序部署为Jar和War文件?
Traditionally, we package a web application as a WAR file and then deploy it into an external server. Doing this allows us to arrange multiple applications on the same server. When CPU and memory were scarce, this was a great way to save resources.
传统上,我们将一个Web应用程序打包成WAR文件,然后部署到外部服务器中。这样做允许我们在同一台服务器上安排多个应用程序。当CPU和内存稀缺的时候,这是一个节省资源的好方法。
But things have changed. Computer hardware is fairly cheap now, and the attention has turned to server configuration. A small mistake in configuring the server during deployment may lead to catastrophic consequences.
但事情已经发生了变化。现在计算机硬件相当便宜,人们的注意力已经转向服务器配置。在部署过程中,配置服务器的一个小错误可能导致灾难性的后果。
Spring tackles this problem by providing a plugin, namely spring-boot-maven-plugin, to package a web application as an executable JAR.
Spring通过提供一个插件,即spring-boot-maven-plugin,将网络应用打包成可执行的JAR,来解决这个问题。
To include this plugin, just add a plugin element to pom.xml:
要包括这个插件,只需在pom.xml中添加一个plugin元素。
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
With this plugin in place, we’ll get a fat JAR after executing the package phase. This JAR contains all the necessary dependencies, including an embedded server. So, we no longer need to worry about configuring an external server.
有了这个插件,我们在执行package阶段后会得到一个胖胖的JAR。这个JAR包含所有必要的依赖,包括一个嵌入式服务器。因此,我们不再需要担心配置外部服务器的问题。
We can then run the application just like we would an ordinary executable JAR.
然后我们可以像运行普通的可执行JAR一样运行该应用程序。
Notice that the packaging element in the pom.xml file must be set to jar to build a JAR file:
注意,pom.xml文件中的packaging元素必须设置为jar以构建JAR文件。
<packaging>jar</packaging>
If we don’t include this element, it also defaults to jar.
如果我们不包括这个元素,它也默认为jar。
To build a WAR file, we change the packaging element to war:
为了建立一个WAR文件,我们把packaging元素改为war。
<packaging>war</packaging>
and leave the container dependency off the packaged file:
并将容器的依赖关系从打包的文件中剔除。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
After executing the Maven package phase, we’ll have a deployable WAR file.
执行Maven package阶段后,我们将得到一个可部署的WAR文件。
Q10. How to Use Spring Boot for Command-Line Applications?
Q10.如何在命令行应用程序中使用Spring Boot?
Just like any other Java program, a Spring Boot command-line application must have a main method.
就像其他Java程序一样,Spring Boot命令行应用程序必须有一个main方法。
This method serves as an entry point, which invokes the SpringApplication#run method to bootstrap the application:
这个方法作为一个入口点,它调用SpringApplication#run 方法来启动应用程序。
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class);
// other statements
}
}
The SpringApplication class then fires up a Spring container and auto-configures beans.
然后SpringApplication类启动Spring容器并自动配置Bean。
Notice we must pass a configuration class to the run method to work as the primary configuration source. By convention, this argument is the entry class itself.
注意我们必须向run方法传递一个配置类,以作为主要的配置源工作。按照惯例,这个参数是入口类本身。
After calling the run method, we can execute other statements as in a regular program.
在调用run方法后,我们可以像普通程序一样执行其他语句。
Q11. What Are Possible Sources of External Configuration?
Q11.外部配置的可能来源是什么?
Spring Boot provides support for external configuration, allowing us to run the same application in various environments. We can use properties files, YAML files, environment variables, system properties and command-line option arguments to specify configuration properties.
Spring Boot提供了对外部配置的支持,使我们能够在不同的环境中运行同一个应用程序。我们可以使用属性文件、YAML文件、环境变量、系统属性和命令行选项参数来指定配置属性。
We can then gain access to those properties using the @Value annotation, a bound object via the @ConfigurationProperties annotation, or the Environment abstraction.
然后我们可以使用@Value注解来访问这些属性,通过@ConfigurationProperties注解或Environment抽象来获得绑定对象。
Q12. What Does It Mean That Spring Boot Supports Relaxed Binding?
Q12.Spring Boot支持宽松的绑定是什么意思?
Relaxed binding in Spring Boot is applicable to the type-safe binding of configuration properties.
Spring Boot中的宽松绑定适用于配置属性的类型安全绑定。
With relaxed binding, the key of a property doesn’t need to be an exact match of a property name. Such an environment property can be written in camelCase, kebab-case, snake_case, or in uppercase with words separated by underscores.
通过宽松的绑定,属性的键不需要与属性名称完全匹配。这样的环境属性可以用camelCase、kebab-case、snake_case或者用大写字母写,用下划线隔开单词。
For example, if a property in a bean class with the @ConfigurationProperties annotation is named myProp, it can be bound to any of these environment properties: myProp, my-prop, my_prop, or MY_PROP.
例如,如果Bean中带有 @ConfigurationProperties 注解的属性被命名为 myProp,它可以被绑定到这些环境属性中的任何一个。myProp, my-prop, my_prop, 或MY_PROP。
Q13. What Is Spring Boot DevTools Used For?
Q13.我们Spring Boot DevTools用于什么?
Spring Boot Developer Tools, or DevTools, is a set of tools making the development process easier.
Spring Boot开发者工具,或称DevTools,是一套使开发过程更容易的工具。
To include these development-time features, we just need to add a dependency to the pom.xml file:
为了包括这些开发时的功能,我们只需要在pom.xml文件中添加一个依赖项。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
The spring-boot-devtools module is automatically disabled if the application runs in production. The repackaging of archives also excludes this module by default. So, it won’t bring any overhead to our final product.
如果应用程序在生产中运行,spring-boot-devtools模块会被自动禁用。归档的重新包装也默认排除了这个模块。所以,它不会给我们的最终产品带来任何开销。
By default, DevTools applies properties suitable to a development environment. These properties disable template caching, enable debug logging for the web group, and so on. As a result, we have this sensible development-time configuration without setting any properties.
默认情况下,DevTools应用适合于开发环境的属性。这些属性禁用了模板缓存,启用了Web组的调试日志,诸如此类。因此,我们有这种合理的开发时配置,而不需要设置任何属性。
Applications using DevTools restart whenever a file on the classpath changes. This is a very helpful feature in development, as it gives quick feedback for modifications.
每当classpath上的文件发生变化时,使用DevTools的应用程序就会重新启动。这在开发中是一个非常有用的功能,因为它可以快速反馈修改。
By default, static resources, including view templates, don’t set off a restart. Instead, a resource change triggers a browser refresh. Notice this can only happen if the LiveReload extension is installed in the browser to interact with the embedded LiveReload server that DevTools contains.
默认情况下,静态资源,包括视图模板,不会引发重新启动。相反,资源变化会触发浏览器刷新。请注意,只有在浏览器中安装了LiveReload扩展,以便与DevTools包含的嵌入式LiveReload服务器进行交互时,这才会发生。
For further information on this topic, please see Overview of Spring Boot DevTools.
有关该主题的进一步信息,请参见Spring Boot DevTools概述。
Q14. How to Write Integration Tests?
Q14.如何编写集成测试?
When running integration tests for a Spring application, we must have an ApplicationContext.
当运行Spring应用程序的集成测试时,我们必须有一个ApplicationContext。
To make our life easier, Spring Boot provides a special annotation for testing — @SpringBootTest. This annotation creates an ApplicationContext from configuration classes indicated by its classes attribute.
为了让我们的生活更轻松,Spring Boot为测试提供了一个特殊注解–@SpringBootTest。这个注解从其classes属性所指示的配置类中创建一个ApplicationContext。
In case the classes attribute isn’t set, Spring Boot searches for the primary configuration class. The search starts from the package containing the test until it finds a class annotated with @SpringBootApplication or @SpringBootConfiguration.
如果没有设置classes属性,Spring Boot会搜索主要的配置类。搜索从包含测试的包开始,直到找到一个用@SpringBootApplication或@SpringBootConfiguration注释的类。
For detailed instructions, check out our tutorial on testing in Spring Boot.
有关详细说明,请查看我们关于在Spring Boot中进行测试的教程。
Q15. What Is Spring Boot Actuator Used For?
Q15.Spring Boot Actuator的用途是什么?
Essentially, Actuator brings Spring Boot applications to life by enabling production-ready features. These features allow us to monitor and manage applications when they’re running in production.
从本质上讲,Actuator通过启用生产就绪的功能,将Spring Boot应用程序带入生活。这些功能使我们能够在应用程序在生产中运行时监控和管理它们。
Integrating Spring Boot Actuator into a project is very simple. All we need to do is include the spring-boot-starter-actuator starter in the pom.xml file:
将Spring Boot Actuator集成到项目中是非常简单的。我们需要做的就是在pom.xml文件中包括spring-boot-starter-actuator启动器。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Spring Boot Actuator can expose operational information using either HTTP or JMX endpoints. But most applications go for HTTP, where the identity of an endpoint and the /actuator prefix form a URL path.
Spring Boot Actuator可以使用HTTP或JMX端点来暴露操作信息。但大多数应用都会选择HTTP,其中端点的身份和/actuator前缀构成一个URL路径。
Here are some of the most common built-in endpoints Actuator provides:
以下是Actuator提供的一些最常见的内置端点。
- env exposes environment properties
- health shows application health information
- httptrace displays HTTP trace information
- info displays arbitrary application information
- metrics shows metrics information
- loggers shows and modifies the configuration of loggers in the application
- mappings displays a list of all @RequestMapping paths
Please refer to our Spring Boot Actuator tutorial for a detailed rundown.
请参考我们的Spring Boot Actuator教程,了解详细情况。
Q16. Which Is Better to Configure a Spring Boot Project — Properties or YAML?
Q16.配置Spring Boot项目时,属性和YAML哪个更好?
YAML offers many advantages over properties files:
与属性文件相比,YAML提供了许多优势。
- More clarity and better readability
- Perfect for hierarchical configuration data, which is also represented in a better, more readable format
- Support for maps, lists and scalar types
- Can include several profiles in the same file (since Spring Boot 2.4.0, this is possible for properties files too)
However, writing it can be a little difficult and error-prone due to its indentation rules.
然而,由于其缩进规则,编写它可能有点困难,而且容易出错。
For details and working samples, please refer to our Spring YAML vs Properties tutorial.
有关详细信息和工作示例,请参考我们的Spring YAML vs Properties 教程。
Q17. What Basic Annotations Does Spring Boot Offer?
Q17.Spring Boot提供哪些基本注解?
The primary annotations that Spring Boot offers reside in its org.springframework.boot.autoconfigure and its sub-packages.
Spring Boot提供的主要注释位于其org.springframework.boot.autoconfigure及其子包中。
Here are a couple of basic ones:
这里有几个基本的。
- @EnableAutoConfiguration – to make Spring Boot look for auto-configuration beans on its classpath and automatically apply them
- @SpringBootApplication – to denote the main class of a Boot Application. This annotation combines @Configuration, @EnableAutoConfiguration and @ComponentScan annotations with their default attributes.
Spring Boot Annotations offers more insight into the subject.
Spring Boot注释提供了对该主题的更多见解。
Q18. How to Change the Default Port in Spring Boot?
Q18.如何改变Spring Boot中的默认端口?
We can change the default port of a server embedded in Spring Boot using one of these ways:
我们可以改变嵌入Spring Boot的服务器的默认端口,使用这些方法之一。
- Using a properties file – We can define this in an application.properties (or application.yml) file using the property server.port.
- Programmatically – In our main @SpringBootApplication class, we can set the server.port on the SpringApplication instance.
- Using the command line – When running the application as a jar file, we can set the server.port as a java command argument:
java -jar -Dserver.port=8081 myspringproject.jar
Q19. Which Embedded Servers Does Spring Boot Support, and How to Change the Default?
Q19.Spring Boot支持哪些嵌入式服务器,以及如何改变默认值?
As of date, Spring MVC supports Tomcat, Jetty and Undertow. Tomcat is the default application server supported by Spring Boot’s web starter.
截至目前,Spring MVC支持Tomcat、Jetty和Undertow。Tomcat是Spring Boot的web启动器支持的默认应用服务器。
Spring WebFlux supports Reactor Netty, Tomcat, Jetty and Undertow with Reactor Netty as default.
Spring WebFlux支持Reactor Netty、Tomcat、Jetty和Undertow,Reactor Netty是默认的。
In Spring MVC, to change the default, let’s say to Jetty, we need to exclude Tomcat and include Jetty in the dependencies:
在Spring MVC中,要改变默认的,比方说Jetty,我们需要排除Tomcat,在依赖关系中包括Jetty。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
Similarly, to change the default in WebFlux to UnderTow, we need to exclude Reactor Netty and include UnderTow in the dependencies.
同样,要把WebFlux中的默认值改为UnderTow,我们需要排除Reactor Netty,把UnderTow列入依赖关系。
Comparing Embedded Servlet Containers in Spring Boot has more details on the different embedded servers we can use with Spring MVC.
比较Spring Boot中的嵌入式Servlet容器有更多关于我们可以使用Spring MVC的不同嵌入式服务器的细节。
Q20. Why Do We Need Spring Profiles?
Q20.为什么我们需要Spring型材?
When developing applications for the enterprise, we typically deal with multiple environments such as Dev, QA and Prod. The configuration properties for these environments are different.
在为企业开发应用程序时,我们通常要处理多个环境,如开发、QA和Prod。这些环境的配置属性是不同的。
For example, we might be using an embedded H2 database for Dev, but Prod could have the proprietary Oracle or DB2. Even if the DBMS is the same across environments, the URLs would definitely be different.
例如,我们可能为开发部使用嵌入式H2数据库,但开发部可能有专有的Oracle或DB2。即使DBMS在不同的环境中是相同的,URLs也肯定会不同。
To make this easy and clean, Spring has the provision of profiles to help separate the configuration for each environment. So, instead of maintaining this programmatically, the properties can be kept in separate files such as application-dev.properties and application-prod.properties. The default application.properties points to the currently active profile using spring.profiles.active so that the correct configuration is picked up.
为了使这一点变得简单和干净,Spring提供了配置文件,以帮助分离每个环境的配置。properties和application-prod.properties。默认的application.properties使用spring.profiles.active指向当前活动的配置文件,以便正确的配置被拾取。
Spring Profiles gives a comprehensive view of this topic.
Spring Profiles给出了关于这个主题的全面看法。
3. Conclusion
3.结论
This article went over some of the most critical questions on Spring Boot that can come up during a technical interview.
本文介绍了技术面试中可能出现的一些关于Spring Boot的最关键问题。
We hope they help land that dream job!
我们希望他们能帮助你找到理想的工作!