Spring Boot interview question collection

Q: What is spring boot?

Answer: Over the years, with the increase of new functions, spring has become more and more complex. Just visit the page https://spring.io/projects , we will see all the spring projects with different functions used in the application. If a new spring project must be started, we must add the build path or maven dependency, configure the application server, and add the spring configuration. Therefore, starting a new spring project requires a lot of work, because at present we must do everything from scratch. Spring Boot is the solution to this problem. Spring boot is built on the existing Spring framework. With spring boot, we can avoid all the boilerplate code and configuration that must be executed before. Therefore, Spring boot helps us to use existing Spring functions more robustly with minimal workload.

Q: What are the advantages of Spring Boot?

Answer: The advantages of Spring Boot are

Reduce the time and workload of development and testing.

Using JavaConfig helps avoid using XML.

Avoid a large number of maven imports and various version conflicts.

Provide alternative development methods.

The default development method is provided for rapid development.

No separate web server is required. This means that you no longer need to start Tomcat, Glassfish, or anything else.

Since there is no web.xml file, less configuration is required. Just add a class with @ configuration annotation, and then add a method with @ bean annotation. Spring will automatically load the object and manage it as usual. You can even add @ Autowired to the bean method to make Spring autowire a dependency required by the bean.

Environment based configuration -- With these attributes, you can transfer them to the application environment you are using: - dspring. profile. active={enclosure}. After loading the main application property file, Spring will load the subsequent application property file at (application - {environment}. properties).

Q: What build tools have you used to develop Spring boot applications?

Answer: Spring Boot applications can be developed using Maven and Gradle.

Q: What is JavaConfig?

Answer: Spring JavaConfig is a product of the Spring community. It provides a pure java method to configure the Spring IoC container. Therefore, it helps to avoid using XML configuration. The advantages of using JavaConfig are:

Object oriented configuration. Because configuration is defined as a class in JavaConfig, users can make full use of the object-oriented features in Java. A configuration class can subclass another configuration class, override its @ Bean method, and so on.

Reduce or eliminate XML configuration. The benefits of external configuration based on the dependency injection principle have been demonstrated. However, many developers are reluctant to switch back and forth between XML and Java. JavaConfig provides developers with a pure java method to configure Spring containers, which is conceptually similar to XML configuration. Technically, it is feasible to use only JavaConfig configuration classes to configure containers, but in practice, many people find it ideal to mix and match JavaConfig with XML.

Type safe refactoring capability. JavaConfig provides a type safe method for configuring Spring containers. Because of Java 5.0's support for generics, beans can now be retrieved by type rather than by name, without any type conversion or string based lookups.

Q: How can I reload my changes when Spring boots without restarting the server?

Answer: This can be achieved through development tools. With this dependency, any changes you save will restart the embedded tomcat. Spring Boot has a DevTools module, which helps improve the working efficiency of developers. One of the key challenges faced by Java developers is to automatically deploy file changes to the server and automatically restart the server. Developers can reload changes at Spring boot time without having to restart the server. This eliminates the need for each manual deployment change. Spring Boot does not have this feature when the first version is released. This is the feature developers need most. 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. Use the following dependencies
org. springframework. boot spring boot devtools true

The following example demonstrates the DevTool dependency usage of auto start and H2 DB console

Q: What is Spring boot actor?

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

Q: How to deploy the Spring Boot application as a war package?

Answer: Spring Boot WAR deployment

Q: What is Docker? How to deploy the Spring bootstrap application to Docker?

Answer:

Deploy Spring based WAR application to Docker

Deploy Spring based JAR applications to Docker

Q: How to disable the security of the actuator endpoint to start in Spring?

Answer: 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 - disable security

Management. security. enabled=false

It is recommended to disable security only when accessing the ACTUATOR endpoint behind the firewall.

Q: How can I run the Spring bootstrap application to a custom port?

Answer: To run the spring boot application on a custom port, you can specify the port in application.properties.

Server. port=8090

Q: What is the ELK stack? How can I use it with Spring Boot?

Answer: The ELK stack consists of three open source products - Elasticsearch, Logstash and Kibana from Elastic.

Elasticsearch is a NoSQL database based on Lucene search engine.

Logstash is a log pipeline tool that accepts input from different sources, performs different transformations, and exports data to different targets. It is a dynamic data collection pipeline, with extensible plug-in ecosystem and strong elastic search synergy

Kibana is a visual UI layer that works on Elastic search.

These three projects are used together for log analysis in various environments. Therefore, Logstash collects and parses logs, elastically searches indexes, and stores this information. Kibana provides a UI layer that provides operational visibility.

Q: Do you use Spring Boot to write test cases?

Answer: SpringBoot provides @ SpringBootTest for writing unit test cases

A simple example of Spring guided unit testing

Q: What is YAML?

Answer: YAML is a human readable data serialization language. It is typically used for configuration files.

Compared with the attribute file, the structure of YAML file is more structured. If we want to add complex attributes to the configuration file, it will not cause too much confusion. As you can see, YAML has hierarchical configuration data.

Using YAML attributes in Spring bootstrapping

Q: How do I implement security for the Spring bootstrap application?

Answer: In order to realize the security of Spring Boot, we use Spring - Boot - starter - security dependency, and must add security configuration. It requires very little code. The Config class must extend WebSecurityConfigurerAdapter and override its methods.

Q: Have you integrated Spring Boot and ActiveMQ?

In order to integrate Spring Boot and ActiveMQ, we use the Spring - Boot - starter - ActiveMQ dependency, which requires little configuration and no template code.

Description of Spring Boot ActiveMQ

Q: Have you integrated Spring Boot and Apache Kafka?

Answer: To integrate Spring Boot and Apache Kafka, we use Spring - Kafka dependencies.

Spring Boot+Apache Kafka Example

Q: How to use Spring guidance to implement paging and sorting?

Answer: It is very simple to use Spring Boot to implement paging. Spring Data JPA is used, which is realized by passing the pageable org.springframe. data.domain. Paging to repository methods.

Spring Guide Paging Description

Q: What is Swagger? Have you implemented it using Spring Boot?

Answer: Swagger is widely used as a visual api. Swagger UI provides an online sandbox environment for front-end developers. In this tutorial, we will use the Springfox implementation of the Swagger 2 specification. Swagger is a tool, specification, and complete framework implementation for generating a visual representation of RESTful Web services. It allows documents to be updated at the same rate as the server. When properly defined through Swagger, users can understand and interact with remote services with minimal implementation logic. So Swagger eliminates the guesswork when invoking services.

Spring Boot+Swagger 2

Q: What are Spring Profiles? How do I implement it using Spring Boot?

Answer: Spring Profiles allows users to register beans according to configuration files (dev, test, prod, etc.). Therefore, when the application is running in development, only some beans can be loaded, and when the application is running in production, only some other beans can be loaded. Suppose our requirement is that the Swagger document is only enabled for QA environments and disabled for all other environments. This can be done using configuration files. Spring Boot makes it easy to use configuration files.

Spring boot+configuration file

Q: What is Spring Boot Batch? How do I implement it using Spring Boot?

Answer: Spring Boot Batch provides the reusable functions necessary for processing a large number of records, including logging/tracking, transaction management, job processing statistics, job restart, job skip, and resource management. It also provides more advanced technical services and features, which will support extremely high capacity and high-performance batch jobs through optimization and partitioning technology. Whether simple or complex, high-capacity batch jobs can use the framework to process large amounts of information in a highly scalable manner.

Spring Boot Batch

Q: What is a FreeMarker template? How do I implement it using Spring Boot?

Answer: FreeMarker is a template engine based on java. It initially focused on generating dynamic web pages using MVC software architecture. The main advantage of using Freemarker is the complete separation of the presentation layer and the business layer. Programmers can handle application code, while designers can handle html page design. Finally, using freemarker, these can be combined to give the final output page.

Example of Spring Boot+FreeMarker

Q: How to use Spring Boot to implement exception handling?

Answer: Spring provides a very useful method to handle exceptions using ControllerAdvice. We will implement a ControlerAdvice class that will handle all exceptions thrown by the controller class.

Spring boot exception handling

Q: What is caching? Have you ever used the caching framework in Spring bootstrapping?

Answer: Cache is an area of local memory. It stores copies of frequently accessed data. Otherwise, it will be very expensive to obtain or calculate these data. Use Hazelcast for caching.

Spring Boot+Hazelcast Example

Question: Do you use Spring Boot to expose SOAP web service endpoints?

Answer: Yes. Use Spring Boot to expose the web service to be used. Use the contract first method to generate classes from wsdl.

Spring Bootstrap+SOAP Web Service Example

Q: How do you use Spring Boot to perform database operations?

Answer: Spring Boot Tutorial Spring Data JPA

Spring bootstrap JDBC example

Q: How to upload files using Spring?

Answer: Spring Boot+example of file upload

Q: How to use Spring Boot to implement interceptors?

Answer: Use Spring MVC HandlerInterceptor to boot with Spring

Q: How to use schedulers under Spring Boot?

Answer: Spring bootstrap task scheduler example

Q: Which initiator maven dependencies have you used?

Answer: You have used different starter dependencies, such as spring boot starter activemq dependency, spring boot starter security dependency, and spring boot starter web dependency.

This helps reduce the number of dependencies and reduces version composition.

Spring Boot Security Example and Description

Q: What is a CSRF attack? How to enable CSRF to protect it?

Answer: CSRF represents cross site request forgery. It is an attack that forces end users to perform unwanted operations on their current authenticated web applications. The CSRF attack is specifically targeted at state change requests, not data theft, because the attacker cannot see the response to the forged request.

Spring Boot Security - Enable CSRF Protection

Q: How to use Spring to guide form login authentication?

Answer: Spring guided form security login Hello World example

Q: What is OAuth2? How do I implement it using Spring Boot?

Answer: Spring Boot+OAuth2 implementation https://www.cnblogs.com/meibaorui/p/9182660.html

Q: What is GZIP? How do I implement it using Spring Boot?

Answer: gzip is a file format and a software application for file compression and decompression.

Spring boot+GZIP compression

Q: Have you ever used the integration framework in Spring boot?

Answer: Apache Camel has been integrated with Spring boot. Start the startup dependency using Apache Camel Spring.

Spring Boot+Apache Camel

Q: What is Apache Freemaker? When do I use it instead of JSP? How to integrate with Spring Boot?

Answer: JSP is tailored for web pages. Freemarker template is a more general template language - it can be used to generate html, plain text, e-mail, etc.

Example of Spring Boot+FreeMarker

### Q: When did you use WebSockets? How do I implement it using Spring Boot?

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

WebSocket is bidirectional -- either the client or the server can send messages.

WebSocket is full duplex -- the communication between client and server is independent of each other.

Single TCP connection - The initial connection uses HTTP, and then the connection is upgraded to a socket based connection. This single connection will then be used for all future communications

Light - WebSocket message data exchange is much lighter than http.

Example of Spring Boot+WebSockets

Q: What is AOP? How can I use it with Spring Boot?

Answer: In the process of software development, functions that span multiple points of the application are called crosscutting concerns. These crosscutting concerns are different from the main business logic of the application. Therefore, separating these crosscutting concerns from business logic is an entry point for aspect oriented programming (AOP).

Spring Boot+AOP Example

Q: What is Apache Kafka? How to integrate with Spring Boot?

Answer: Apache Kafka is a distributed publish subscribe messaging system. It is a scalable, fault-tolerant, publish subscribe messaging system that enables us to build distributed applications. This is a top-level Apache project. Kafka is applicable to offline and online message consumption.

Spring Boot+Apache Kafka Example

Q: How do we monitor all Spring Boot microservices?

Answer: Spring Boot provides the actor endpoint to monitor the indicators of a single microservice. These endpoints are very helpful for obtaining information about applications, such as whether applications are started and whether their components (such as databases) work properly. However, one of the main disadvantages or difficulties of using the actor interface is that we must hit these interfaces one by one to understand the state or health of the application. Assuming that microservices involve 50 applications, administrators will have to hit the actor endpoints of all 50 applications. To help us deal with this situation, we will use the https://github.com/codecentric/springing-boot-admin Open source project of.

It is built on the Spring Boot Actuator and provides a web UI, enabling us to visualize the indicators of multiple applications.

Spring Boot Admin

Q: Have you ever used Spring Cloud components in Spring boot?

Answer: I have used Netflix Eureka and other Spring Cloud components for service registration, and the ribbon is used for load balancing.

Spring Boot+Cloud Components

Spring Cloud interview Questions

Q: How to deploy the Spring Boot application to the Pivot Cloud Foundry (PCF)?

A: Deploying Spring Boot Application to PCF

Q: How to deploy the Spring Boot+MySQL application to the Pivot Cloud Foundry (PCF)?

A: Pivot Cloud Foundry Tutorial - Deploying Spring Boot+MySQL Application to PCF

Q: How to deploy the Spring Boot+RabbitMQ application to the Pivot Cloud Foundry (PCF)?

A: Pivot Cloud Foundry Tutorial - Deploying Spring Boot+RabbitMQ Application to PCF

相关推荐
xoxo-Rachel3 分钟前
(超级详细!!!)解决“com.mysql.jdbc.Driver is deprecated”警告:详解与优化
java·数据库·mysql
乌啼霜满天2495 分钟前
JDBC编程---Java
java·开发语言·sql
色空大师18 分钟前
23种设计模式
java·开发语言·设计模式
闲人一枚(学习中)18 分钟前
设计模式-创建型-建造者模式
java·设计模式·建造者模式
2202_7544215436 分钟前
生成MPSOC以及ZYNQ的启动文件BOOT.BIN的小软件
java·linux·开发语言
蓝染-惣右介38 分钟前
【MyBatisPlus·最新教程】包含多个改造案例,常用注解、条件构造器、代码生成、静态工具、类型处理器、分页插件、自动填充字段
java·数据库·tomcat·mybatis
小林想被监督学习39 分钟前
idea怎么打开两个窗口,运行两个项目
java·ide·intellij-idea
HoneyMoose41 分钟前
IDEA 2024.3 版本更新主要功能介绍
java·ide·intellij-idea
我只会发热43 分钟前
Java SE 与 Java EE:基础与进阶的探索之旅
java·开发语言·java-ee
是老余44 分钟前
本地可运行,jar包运行错误【解决实例】:通过IDEA的maven package打包多模块项目
java·maven·intellij-idea·jar