Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Share questions and answers about spring boot interview

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "sharing spring boot interview questions and answers". In daily operation, I believe many people have doubts about sharing spring boot interview questions and answers. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about sharing spring boot interview questions and answers! Next, please follow the editor to study!

1. What is Spring Boot?

The traditional SSM/SSH framework combination configuration is tedious and bloated, and there are many repetitive and templated configurations in different projects, which seriously reduces the development efficiency of Java engineers, while Spring Boot can easily create Spring-based, independent, production-level applications. By providing a series of automatically configured Starter for the Spring family and some third-party libraries, developers can quickly build a Spring-based application.

Spring Boot brings the increasingly bloated Java code back to simplicity. When used with Spring Cloud, it can also play a more powerful role.

2. How to solve the cross-domain problem in Spring Boot?

Cross-domain can be solved through JSONP at the front end, but JSONP can only send GET requests, but cannot send other types of requests. In RESTful-style applications, it is very fishy, so we recommend (CORS,Cross-origin resource sharing) to solve cross-domain problems at the back end.

This solution is not specific to Spring Boot. In the traditional SSM framework, we can solve cross-domain problems through CORS, but we used to configure CORS in XML files, but now we solve cross-domain problems through @ CrossOrigin annotations.

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

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

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

The bootstrap profile has the following application scenarios.

When ① uses Spring Cloud Config configuration center, you need to add the 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

4. How to run Spring Boot

① directly executes the main method to run

② runs with the Maven / Gradle plug-in

③ is packed into jar packages and run directly through the java-jar command.

5. The principle of Spring Boot automatic configuration.

Add @ SpringBootApplication or @ EnableAutoConfiguration to the main method of the Spring program. Automatically go to maven to read the spring.factories file in each starter, which is configured with all the bean that needs to be created in the spring container.

Spring Boot scans the JAR package that the project depends on at startup for the JAR that contains the spring.factories file.

Load the AutoConfigure class based on the spring.factories configuration.

Automatically configure and inject Bean into Spring Context according to the conditions of the @ Conditional annotation.

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

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

7. What are the advantages of Spring Boot?

① reduces development and testing time and effort.

② uses JavaConfig to help avoid using XML.

③ avoids a large number of Maven imports and various version conflicts.

④ provides advice on developing methods.

⑤ starts development quickly by providing default values.

⑥ does not have a separate Web server required. This means you no longer need to start Tomcat,Glassfish or anything else.

⑦ requires less configuration: because there is no web.xml file. Simply add a class annotated with @ Configuration, then add a 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 so that Spring automatically loads the required dependencies.

⑧ environment-based configuration: using these properties, you can pass the environment you are using to your application:-Dspring.profiles.active = {enviornment}. After loading the main application properties file, Spring loads subsequent application properties files in (application {environment} .properties).

8. How do I reload the changes on the Spring Boot without restarting the server?

This can be done using the DEV tool. With this dependency, you can save any changes and the embedded tomcat will restart.

Spring Boot has a development tool (DevTools) module that helps increase developer productivity. One of the main challenges for Java developers is to automatically deploy file changes to the server and restart the server automatically.

Developers can reload changes on the Spring Boot without restarting the server. This eliminates the need to deploy changes manually each time. Spring Boot didn't have this feature when it released its first version.

This is the feature that developers need most. The DevTools module fully meets the needs of developers. This module will be disabled in the production environment. It also provides the H2 database console to better test the application.

9. What is the monitor in Spring Boot?

Spring boot actuator is one of the important functions in the spring startup framework. The Spring boot Monitor helps you access the current status of running applications in a production environment.

There are several indicators that must be checked and monitored in the production environment. Even though some external applications may be using these services to trigger alert messages to relevant people. The monitor module exposes a set of REST endpoints that can be accessed directly as HTTP URL to check status.

10. How to achieve the security of Spring Boot applications?

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

At this point, the study of "sharing spring boot interview questions and answers" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report