How to understand the convention in SpringBoot is better than configuration

Get technical dry goods and industry information for the first time!

How to understand the convention in SpringBoot is better than configuration

About two years ago, a colleague told me, what does it mean that convention is better than configuration in SpringBoot? Is it not necessary to configure it? Doesn't need to be configured. What is the configuration file?

How to understand the convention in SpringBoot is better than configuration
Regarding this question, I believe that it has bothered many people, and many people will be asked during the interview. Take a time today, let's discuss and discuss how to understand this sentence!

Convention is better than configuration, and many people interpret it as: convention is greater than configuration, convention is better than configuration, habit is greater than configuration, etc. But they all show a meaning, not zero configuration. In other words, zero configuration does not mean that there is no configuration at all, but to reduce configuration through conventions.

Convention is better than configuration is a simple concept. The system, class library, and framework should assume reasonable default values ​​instead of requiring unnecessary configuration. In most cases, you will find that using the default values ​​provided by the framework will make your project development more efficient.

Convention is better than configuration. It is not a new routine, new technology, new idea. But it has always existed before, and SpringBoot just amplifies it, and truly achieves that the convention is better than the configuration.

For example, we are in the daily development process. If you have an xttblog table, there may be an entity class of Xttblog corresponding to it. This is actually a convention.

In SpringBoot, when we import a spring-boot-starter-web. It will automatically help us import Spring MVC related dependencies (including Jackson supported by Json and Hibernate Validator for data validation) and a built-in Tomcat container, which makes it possible to run one directly through the main method or JAR package during the development phase WEB project.

SpringBoot agrees that when you import spring-boot-starter-web, it is agreed that you are a web development environment. When you are a web environment, you have agreed that you will use SpringMVC (Struts2 and the like are goodbye, because they are not in-person, and they are indeed not as high as SpringMVC). As for the others, you have agreed that you will need them, and they will be imported by default. When you feel inappropriate, you can use fewer changes to meet your needs.

Spring is promoting the design concept of "Convention is better than configuration", and it has started with Spring's annotated version. The introduction of annotations is to reduce some default configurations, and the introduction of annotations also represents the beginning of simplified configuration. The official said that the foundation based on spring is this fact.

SpringBoot agreed to reduce dependency in the form of starter, so many commonly used starters have been launched one after another.

Convention is better than configuration. It is also reflected in our actual lives. For example, we agreed to drive on the right, and we agreed to hold chopsticks in the right hand from childhood. It is SprigBoot's small "promise" and its great effect that more and more people fall in love with it.

Guess you like

Origin blog.51cto.com/15127565/2666198