The 22 spring boot interview questions shared by Ali P7 boss, finally came over for nothing!

Spring Boot interview questions

1. What is Spring Boot?

2. What are the advantages of Spring Boot?

3. What is JavaConfig?

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

5. What is the monitor in Spring Boot?

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

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

8. What is YAML?

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

10. How to integrate Spring Boot and ActiveMQ?

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

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

13. What is Spring Profiles?

14. What is Spring Batch?

15. What is a FreeMarker template?

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

17. What starter maven dependencies did you use?

18. What is a CSRF attack?

19. What is WebSockets?

20. What is AOP?

21. What is Apache Kafka?

22. How do we monitor all Spring Boot microservices?

 

1. What is Spring Boot?

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 functions more robustly with the least amount of work.

 

2. What are the advantages of Spring Boot?

The advantages of Spring Boot are:

1. Reduce development and testing time and effort.

2. Using JavaConfig helps to avoid the use of XML.

3. Avoid a large number of Maven imports and various version conflicts.

4. Provide advice and development methods.

5. Quickly start development by providing default values.

6. There is no need for a separate web server. This means you no longer need to start Tomcat, Glassfish or anything else.

7. Less configuration is needed 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.

8. Environment-based configuration Using these properties, you can pass the environment you are using to the application: -Dspring.profiles.active = {enviornment}. After loading the main application property file, Spring will load the subsequent application property file in (application{environment}.properties).

 

3. 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 the use of 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. One 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 that mixing and matching JavaConfig with XML is ideal.

(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 name, without any casting or string-based lookup.

 

4. 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 facing Java developers is to automatically deploy file changes to the server and automatically restart the server. Developers can reload 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 most requested feature for 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.

 
  1. <dependency>

  2. <groupId>org.springframework.boot</groupId>

  3. <artifactId>spring-boot-devtools</artifactId>

  4. <optional>true</optional>

  5.  

 

5. 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 the running application in the production environment. There are several indicators that must be checked and monitored in the 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 the status.

 

6. 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 when the actuator endpoint is accessed behind a firewall.

 

7. 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

 

8. What is YAML?

YAML is a human-readable data serialization language. It is usually used for configuration files. Compared with the property 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.

 

9. 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.

 

10. 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.

 

11. 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.

 

12. 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.

 

13. 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.

 

14. What is Spring Batch?

Spring Boot Batch provides reusable functions, these functions 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, extremely high batch and high-performance batch processing jobs can be realized. Simple and complex large batch processing jobs can use the framework to process important and large amounts of information in a highly scalable manner.

 

15. 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. The programmer can handle the application code, and the designer can handle the html page design. Finally, use freemarker to combine these to give the final output page.

 

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

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

 

17. 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.

 

18. 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 the attacker cannot view the response to the forged request.

 

19. 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-use WebSocket client or server to 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.

 

20. 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).

 

21. 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.

 

22. 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 the monitor 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 Spring Boot Actuator, which provides a Web UI that allows us to visualize the metrics of multiple applications.

It took 1 month to sort out 1,000 java interview questions for multiple companies in 2020 and more than 400 pages of pdf documents. Welcome everyone to pay attention to my official account: Kylin changes bugs, articles will be updated in it, and the sorted information will also be placed inside.

In response to the knowledge points asked in the above interview, I have summarized most of the interview questions and answers involved in the Internet company’s Java programmer interview. Documents and architecture materials are shared with everyone. I hope to help you before the interview. Reviewing and finding a good job also saves everyone's time to search for information on the Internet to learn.

 

At last

Welcome everyone to communicate together, it is not easy to organize the information, if you like the article, remember to follow me and give me a like, thank you for your support!

Guess you like

Origin blog.csdn.net/QLCZ0809/article/details/112253564