Spring-boot-devtools used in SpringBoot cannot be applied to the production environment

table of Contents

Maven scope configuration related parameter description

Spring-boot-devtools deprecated configuration


Such as the title: This problem is the introduction of production during development. If there is a bug in the program, then spring-boot-devtools will have a similar application restart process when throwing an unhandled exception (when modifying a class, you can see the devtools in the local The development environment will close the application and restart), causing the data source to shut down. Here are two issues that must be paid attention to in production:

  • try{}finlly{} has no catch, which will cause serious swallowing exceptions
  • The spring-boot-devtools hot deployment plug-in is used in the project, which causes the application to restart under abnormal conditions (the Druid data source is closed at this time, and the update can no longer be performed)

Maven scope configuration related parameter description

The following content reference: https://maven.apache.org/pom.html

scope : This element refers to the classpath of the task at hand (compilation and runtime, testing, etc.) and how to restrict the transitivity of dependencies. There are five scopes:

  • compile -This is the default scope, used if not specified. Compilation dependencies are available in all classpaths. In addition, these dependencies are propagated to related projects.
  • provided -This is a lot like compilation, but indicates that you want the JDK or container to provide it at runtime. It is only available on the compile and test classpath and is not transferable.
  • runtime -This scope indicates that the dependency is not necessary for compilation, but necessary for execution. It is in the runtime and test classpath, but not in the compilation classpath.
  • test -This range indicates that the dependency is not necessary for the normal use of the application, and is only available during the test compilation and execution phase. It is not transitive.
  • system -This scope is similar, providedexcept that a JAR that explicitly contains it must be provided. The artifact is always available and will not be found in the repository.

 Note: Knowing the scope is definitely good for us to use maven.

Spring-boot-devtools deprecated configuration

 <!-- 本地热部署插件:慎用-容易导致应用重启数据丢失 -->
       <!-- <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <version>2.2.1.RELEASE</version>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>-->

Through the understanding of the scope configuration type, we know that the runtime will be executed during the execution of the program, which also satisfies the automatic class overloading condition when the devtools is modified or throws an exception.

In the actual production environment, we can set the scope to provided, which is why we see many open source framework examples using the provided domain.

 

Guess you like

Origin blog.csdn.net/boonya/article/details/114144276