📜  Spring Boot – Starter Parent(1)

📅  最后修改于: 2023-12-03 15:35:03.062000             🧑  作者: Mango

Spring Boot – Starter Parent

Spring Boot is a popular Java framework designed to simplify the setup and development of new Spring-based applications. One of its key features is the use of starter dependencies, which provide a convenient way to configure commonly used components and services with minimal configuration.

What is Starter Parent?

Starter Parent is a special dependency that serves as the parent of all other Spring Boot projects. It provides a set of common configurations, plugins, and dependencies that are required by most Spring Boot projects. By using Starter Parent, developers can avoid the need to manually configure many aspects of a new project, and can focus on writing code that delivers business value.

How does Starter Parent work?

When you create a new Spring Boot project, you can specify Starter Parent as the parent POM for your project. This will inherit the common configurations, plugins, and dependencies from Starter Parent into your project.

Here is an example of how to specify Starter Parent in your Maven POM:

<parent>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-parent</artifactId>
   <version>2.5.4</version>
</parent>

By default, Starter Parent configures many aspects of a Spring Boot application, such as logging, testing, packaging, and resource filtering. It also provides a default set of dependencies, including Spring Framework, which is the core component of Spring Boot.

How to customize Starter Parent?

Although Starter Parent provides a useful set of defaults, you may want to customize it for your specific needs. Fortunately, Starter Parent allows for customization by overriding its properties or by selectively including additional dependencies.

Here is an example of how to override the default logging configuration using the logback-spring.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
   <include resource="org/springframework/boot/logging/logback/defaults.xml" />

   <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
      <encoder>
         <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
      </encoder>
   </appender>

   <root level="INFO">
      <appender-ref ref="STDOUT" />
   </root>
</configuration>

In addition to overriding properties and including custom dependencies, Starter Parent also allows for the use of profiles to support different configurations for different environments.

Conclusion

Spring Boot Starter Parent is a powerful tool that simplifies the setup and development of new Spring-based applications. Its use of starter dependencies provides a convenient way to configure commonly used components and services with minimal effort. As a result, using Starter Parent can help developers focus on writing code that delivers business value, rather than on manually configuring their projects.