"Spring Boot real" three: Custom Configuration

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/yuan1164345228/article/details/94839753

This chapter includes three knowledge points:

  • Override automatic configuration Bean
  • With external configuration properties
  • Custom Error Pages

In this chapter we will see the impact of the automatic configuration of two ways - using explicit configuration and use of property coverage to fine configuration. We will also see how to use Spring Boot hooks provided by the introduction of a custom error page.

3.1  covering Spring Boot autoconfiguration

In most cases, automatically configures the Bean just to meet your needs, you do not need to cover them. However, in some cases, Spring Boot not be well inferred autoconfiguration Shihai.

For example, when you add the security features in the application, the security configuration is not universal, application security around there are many decisions to be done, Spring Boot can not make decisions for you. Although Spring Boot to provide some basic security configuration automatically, but you still need to cover yourself some configuration to meet specific security requirements.

Want to know how to use explicit configuration to override the automatic configuration, we start reading the list of applications to add Spring Security to start. After about automatic configuration provides what, let's cover the basic security configurations to meet the needs of a particular scene.

3.1.1 application protection

First, add a Security started dependence. If you use Maven , then you want to project the block, add the following :

After the re-run to build the application, which is now a secure Web application, Classpath there Spring Security , the auto-configuration will be able to intervene to create a basic Spring Security configuration.

 

Guess you like

Origin blog.csdn.net/yuan1164345228/article/details/94839753