JD Interviewer: For these 20 Spring Boot interview questions, I change the question every time.

I interviewed some people, and they said on their resumes that they are familiar with Spring Boot, or that they are learning Spring Boot. When I asked them, they were only at the simple use stage. Many things were not clear, and I was disappointed with the interviewer. To know about spring boot, as long as you write on your resume, the interviewer will usually ask, which can be said to be a key point. At the same time, I also compiled an interview question about spring boot. Of course, not only boot, but also other java knowledge points.

Friends in need can click: click this! Click this! , Code: csdn.

Insert picture description here

Below, I will give you a summary of the Spring Boot interview questions, which I often use to ask interviewers, I hope it will be helpful to you.

1. What is Spring Boot?

Spring Boot is a sub-project under the Spring open source organization. It is a one-stop solution for Spring components. It mainly simplifies the difficulty of using Spring, saves heavy configuration, provides various starters, and developers can quickly get started.

For more details about Spring Boot, please see this article "What is Spring Boot?".

2. Why use Spring Boot?

Spring Boot has many advantages, such as:

  • Operate independently
  • Simplified configuration
  • Automatic configuration
  • No code generation and XML configuration
  • Application monitoring
  • Easy

Spring Boot has so many advantages in one, is there any reason not to use it?

3. What are the core configuration files of Spring Boot? What is the difference between them?

The core configuration files of Spring Boot are application and bootstrap configuration files.

The application configuration file is easy to understand and is mainly used for automatic configuration of Spring Boot projects.

The bootstrap configuration file has the following application scenarios.

When using Spring Cloud Config configuration center, you need to add configuration properties connected to the configuration center in the bootstrap configuration file to load the configuration information of the external configuration center;

Some fixed attributes that cannot be overridden;

Some encryption/decryption scenarios;

For details, please see this article "Detailed Explanation of Spring Boot Core Configuration File".

4. What are the formats of Spring Boot configuration files? What is the difference between them?

The difference between .properties and .yml is mainly in the writing format.

1).properties

app.user.name = javastack

2) .ly

app: user: name: javastack

In addition, the .yml format does not support @PropertySource annotation import configuration.

5. What is the core annotation of Spring Boot? Which annotations are mainly composed of?

The annotation above the startup class is @SpringBootApplication, which is also the core annotation of Spring Boot. The main combination includes the following 3 annotations:

@SpringBootConfiguration: Combines @Configuration annotations to realize the function of configuration files.

@EnableAutoConfiguration: Turn on the automatic configuration function, or turn off an automatic configuration option, such as turning off the data source automatic configuration function: @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class }).

@ComponentScan: Spring component scanning.

6. What are the ways to enable Spring Boot features?

1) Inherit the spring-boot-starter-parent project

2) Import spring-boot-dependencies project dependencies

For details, please refer to this article "Two Ways to Start Spring Boot".

7. Does Spring Boot need a separate container to run?

No need, built-in containers such as Tomcat/ Jetty.

8. What are the ways to run Spring Boot?

1) Command for packaging or run in a container

2) Run with Maven/Gradle plugin

3) Execute the main method directly

9. What is the principle of Spring Boot automatic configuration?

Annotation @EnableAutoConfiguration, @Configuration, @ConditionalOnClass is the core of automatic configuration. First, it must be a configuration file, and secondly, it is automatically configured according to whether there is this class in the class path.

For details, see this article "Spring Boot automatic configuration principle, actual combat".

10. What is the directory structure of Spring Boot?

cn ± javastack ± MyApplication.java | ± customer | ± Customer.java | ± CustomerController.java | ± CustomerService.java | ± CustomerRepository.java | ± order ± Order.java ± OrderController.java ± OrderService.java ± OrderRepository.java

This directory structure is the mainstream and recommended practice, and the @SpringBootApplication annotation is added to the main entry class to enable Spring Boot's various capabilities, such as automatic configuration and component scanning. For details, see this article "Introduction to Spring Boot Main Class and Directory Structure".

11. How do you understand Starters in Spring Boot?

Starters can be understood as a starter. It contains a series of dependency packages that can be integrated into the application. You can integrate Spring and other technologies in one stop without having to look for sample codes and dependency packages everywhere. If you want to use Spring JPA to access the database, just add the spring-boot-starter-data-jpa starter dependency.

Starters contains many dependencies that need to be used in projects, they can run quickly and continuously, and they are a series of supported management transitive dependencies. For details, please see this article "Spring Boot Starters".

12. How to run some specific code when Spring Boot starts?

You can implement the interface ApplicationRunner or CommandLineRunner, these two interfaces are implemented in the same way, they both only provide a run method, please see this article "Spring Boot Runner Starter" for details.

13. What are the ways to read configuration in Spring Boot?

Spring Boot can bind variables through @PropertySource, @Value, @Environment, @ConfigurationProperties. For details, please see this article "Several Ways to Read Configuration in Spring Boot".

14. What logging frameworks does Spring Boot support? Which is the recommended and default logging framework?

Spring Boot supports Java Util Logging, Log4j2, Lockback as the logging framework. If you use Starters, Spring Boot will use Logback as the default logging framework. For details, please see this article "Spring Boot Log Integration".

15. In what ways does SpringBoot implement hot deployment?

There are two main ways:

  • Spring Loaded
  • Spring-boot-devtools

16. How do you understand the Spring Boot configuration loading sequence?

In Spring Boot, there are several ways to load configuration.

1) properties file;

2) YAML file;

3) System environment variables;

4) Command line parameters;

and many more……

For details, please see this article "Detailed Explanation of Spring Boot Configuration Loading Order".

17. How does Spring Boot define multiple sets of different environment configurations?

Provide multiple sets of configuration files, such as:

applcation.properties application-dev.properties application-test.properties application-prod.properties

Specify a specific configuration file at runtime. For details, please see this article "Spring Boot Profile Different Environment Configuration".

18. Is Spring Boot compatible with old Spring projects and how to do it?

Compatible, use @ImportResource annotation to import old Spring project configuration files.

19. What are the ways to protect Spring Boot applications?

  • Use HTTPS in production
  • Use Snyk to check your dependencies
  • Upgrade to the latest version
  • Enable CSRF protection
  • Use content security policies to prevent XSS attacks

20. What new features does Spring Boot 2.X have? What is the difference with 1.X?

  • Configuration changes
  • JDK version upgrade
  • Third-party library upgrade
  • Reactive Spring programming support
  • HTTP/2 support
  • Configure attribute binding
  • More improvements and enhancements...

Finally, free Java architecture learning materials are provided. The learning technology content includes: Spring, Dubbo, MyBatis, RPC, source code analysis, high concurrency, high performance, distributed, performance optimization, microservice advanced architecture development, etc.

Friends in need can click: click this! Click this! , Code: csdn.

There are also Java core knowledge points + a full set of architect learning materials and videos + first-line interview books + interview resume templates can be obtained + Ali Meituan Netease Tencent Xiaomi Iqiyi Kuaishou Bilibili interview questions + Spring source code collection + Java architecture Practical e-book + 2020 latest interview questions from major manufacturers.
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_48011329/article/details/109625772