This is the Spirng boot that you must master to learn Java! Have you mastered the 21 key technical questions?

Preface

Over the years, with the addition of new features, spring has become more and more complex. Visit the spring official website page, we will see all the different functions of the Spring project that can be used in our application. If a new Spring project must be started, we must add the build path or add Maven dependencies, configure the application server, and add spring configuration. Therefore, starting a new spring project requires a lot of effort, because we must now do everything from scratch.
Spring Boot is the solution to this problem. Spring Boot has been built on top of the existing spring framework. With spring boot, we avoid all the boilerplate code and configuration that we had to do before. Therefore, Spring Boot can help us use the existing Spring features more robustly with the least amount of work.

Insert picture description here

Spring Boot interview questions

1. What are the advantages of Spring Boot?

The advantages of Spring Boot are:

  • Reduce development and testing time and effort.
  • Using JavaConfig helps to avoid the use of XML.
  • Avoid a large number of Maven imports and various version conflicts.
  • Provide advice on development methods.
  • Start development quickly by providing default values.
  • No separate web server is required. This means you no longer need to start Tomcat, Glassfish or anything else.
  • Less configuration is required because there is no web.xml file. Just add the class annotated with @Configuration, and then add the method annotated with @Bean, and Spring will automatically load the object and manage it as before. You can even add @Autowired to the bean method to make Spring automatically load the required dependencies.
  • Using these properties for environment-based configuration, you can pass the environment you are using to the application: -Dspring.profiles.active = {enviornment}. After loading the main application properties file, Spring will load the subsequent application properties file in (application{environment}.properties).

2. What is JavaConfig?

Spring JavaConfig is a product of the Spring community. It provides a pure Java method for configuring the Spring IoC container. So it helps to avoid using XML configuration. The advantages of using JavaConfig are:

(1) Object-oriented configuration. Since configuration is defined as a class in JavaConfig, users can take full advantage of the object-oriented features in Java. A configuration class can inherit another, override its @Bean method, etc.

(2) Reduce or eliminate XML configuration. The benefits of externalized configuration based on the principle of dependency injection have been proven. However, many developers do not want to switch back and forth between XML and Java. JavaConfig provides developers with a pure Java method to configure the Spring container similar to the XML configuration concept. From a technical point of view, it is feasible to use only the JavaConfig configuration class to configure the container, but in fact many people think it is ideal to mix and match JavaConfig with XML.

(3) Type safety and refactoring friendly. JavaConfig provides a type-safe way to configure the Spring container. Thanks to Java 5.0's support for generics, beans can now be retrieved by type instead of by name, without any casting or string-based lookup.

3. How to reload the changes on Spring Boot without restarting the server?

This can be achieved using the DEV tool. With this dependency, you can save any changes and the embedded tomcat will restart. Spring Boot has a development tools (DevTools) module, which helps improve the productivity of developers. One of the main challenges faced by Java developers is to automatically deploy file changes to the server and automatically restart the server. Developers can reload the changes on Spring Boot without restarting the server. This will eliminate the need to manually deploy changes each time. Spring Boot did not have this feature when it released its first version. This is the feature most needed by developers. The DevTools module fully meets the needs of developers. This module will be disabled in the production environment. It also provides an H2 database console to better test applications.

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>

4. What is the monitor in Spring Boot?

Spring boot actuator is one of the important functions in the spring boot framework. The Spring boot monitor helps you access the current state of running applications in the production environment. Several indicators must be checked and monitored in a production environment. Even some external applications may be using these services to trigger alert messages to relevant personnel. The monitor module exposes a set of REST endpoints that can be directly accessed as HTTP URLs to check status.

5. How to disable Actuator endpoint security in Spring Boot?

By default, all sensitive HTTP endpoints are secure, and only users with the ACTUATOR role can access them. Security is implemented using the standard HttpServletRequest.isUserInRole method. We can use to disable security. It is only recommended to disable security if the actuator endpoint is accessed behind a firewall.

6. How to run Spring Boot applications on custom ports?

In order to run Spring Boot applications on a custom port, you can specify the port in application.properties. server.port = 8090

7. What is YAML?

YAML is a human-readable data serialization language. It is usually used for configuration files. Compared with the properties file, if we want to add complex properties to the configuration file, the YAML file is more structured and less confusing. It can be seen that YAML has hierarchical configuration data.

8. How to realize the security of Spring Boot application?

In order to achieve the security of Spring Boot, we use the spring-boot-starter-security dependency, and security configuration must be added. It requires very little code. The configuration class will have to extend WebSecurityConfigurerAdapter and override its methods.

9. How to integrate Spring Boot and ActiveMQ?

For integrating Spring Boot and ActiveMQ, we use dependencies. It requires very little configuration and no boilerplate code.

10. How to use Spring Boot to implement paging and sorting?

Using Spring Boot to implement paging is very simple. Use Spring Data-JPA to pass pageable to the repository method.

11. What is Swagger? Have you implemented it with Spring Boot?

Swagger is widely used to visualize APIs, using Swagger UI to provide online sandboxes for front-end developers. Swagger is a tool for generating visual representations of RESTful Web services, specification and complete framework implementation. It enables documents to be updated at the same speed as the server. When correctly defined through Swagger, consumers can use the least amount of implementation logic to understand and interact with remote services. Therefore, Swagger eliminates guesswork when calling services.
Insert picture description here

12. What is Spring Profiles?

Spring Profiles allows users to register beans based on configuration files (dev, test, prod, etc.). Therefore, when the application is running in development, only certain beans can be loaded, while in PRODUCTION, certain other beans can be loaded. Suppose our requirement is that the Swagger document is only applicable to the QA environment, and all other documents are disabled. This can be done using configuration files. Spring Boot makes it very easy to use configuration files.

13. What is Spring Batch?

Spring Boot Batch provides reusable functions that are very important when processing a large number of records, including log/tracing, transaction management, job processing statistics, job restart, skip, and resource management. It also provides more advanced technical services and functions, through optimization and partitioning technology, can achieve extremely high batch and high-performance batch jobs. Simple and complex large batch processing jobs can use the framework to process important and large amounts of information in a highly scalable manner.

14. What is a FreeMarker template?

FreeMarker is a Java-based template engine that initially focused on the use of MVC software architecture for dynamic web page generation. The main advantage of using Freemarker is the complete separation of the presentation layer and the business layer. Programmers can handle application code, and designers can handle html page design. Finally, use freemarker to combine these to give the final output page.

15. How to use Spring Boot to implement exception handling?

Spring provides a very useful way to handle exceptions using ControllerAdvice. We implement a ControlerAdvice class to handle all exceptions thrown by the controller class.

16. What starter maven dependencies did you use?

Some of the following dependencies are used

spring-boot-starter-activemq

spring-boot-starter-security

This helps to increase fewer dependencies and reduce version conflicts.

17. What is a CSRF attack?

CSRF stands for cross-site request forgery. This is an attack that forces the end user to perform unwanted actions on the currently authenticated web application. CSRF attacks specifically target state change requests, not data theft, because attackers cannot view responses to forged requests.

18. What is WebSockets?

WebSocket is a computer communication protocol that provides a full-duplex communication channel through a single TCP connection.

1. WebSocket is bidirectional-using WebSocket client or server can initiate message sending.

2. WebSocket is full-duplex-client and server communication are independent of each other.

3. Single TCP connection-the initial connection uses HTTP, and then this connection is upgraded to a socket-based connection. Then this single connection is used for all future communications

4. Light-Compared with http, WebSocket message data exchange is much lighter.

19. What is AOP?

In the software development process, functions that span multiple points of an application are called cross-problems. These cross-cutting issues are different from the main business logic of the application. Therefore, separating these crosscutting concerns from business logic is the place for aspect-oriented programming (AOP).

20. What is Apache Kafka?

Apache Kafka is a distributed publish-subscribe messaging system. It is a scalable, fault-tolerant publish-subscribe messaging system, which enables us to build distributed applications. This is an Apache top-level project. Kafka is suitable for offline and online message consumption.

21. How do we monitor all Spring Boot microservices?

Spring Boot provides monitor endpoints to monitor the metrics of each microservice. These endpoints are useful for obtaining information about applications (such as whether they have been started) and whether their components (such as databases, etc.) are functioning properly. However, one of the main disadvantages or difficulties of using monitors is that we must open the knowledge points of the application separately to understand its status or health. Imagine a microservice involving 50 applications. The administrator will have to hit the execution terminals of all 50 applications. To help us deal with this situation, we will use the open source project located at. It is built on the Spring Boot Actuator, which provides a Web UI that allows us to visualize the metrics of multiple applications.

Off topic

This is the end of this sharing about Spring boot. Due to space limitations, only a small part of the content is released. Recently, it is the best time to find a job. I want to get more spring microservice-related questions and interviews with major vendors. For questions, you can click here to get the information, code: qf The
following is a screenshot of some of the information (all the information has been integrated into a document, and the pdf is compressed and packaged).

Insert picture description here

Guess you like

Origin blog.csdn.net/S11035762/article/details/108697248