此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Boot 3.3.1! |
此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Boot 3.3.1! |
该插件包含一个运行目标,可用于从命令行启动应用程序,如以下示例所示:
$ mvn spring-boot:run
可以使用参数指定应用程序参数,有关详细信息,请参阅使用应用程序参数。arguments
应用程序在分叉进程中执行,在命令行上设置属性不会影响应用程序。
如果需要指定一些 JVM 参数(用于调试目的),可以使用该参数,有关详细信息,请参阅调试应用程序。
此外,还明确支持系统属性和环境变量。jvmArguments
由于启用配置文件很常见,因此有专用属性提供快捷方式,请参阅指定活动配置文件。profiles
-Dspring-boot.run.jvmArguments="-Dspring.profiles.active=dev"
Spring Boot 是一个模块,用于在处理 Spring Boot 应用程序时改善开发时体验。
若要启用它,只需将以下依赖项添加到项目中:devtools
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
运行时,它会在重新编译应用程序时检测到更改并自动刷新它。
这不仅适用于资源,也适用于代码。
它还提供了一个 LiveReload 服务器,以便它可以在事情发生变化时自动触发浏览器刷新。devtools
还可以将 Devtools 配置为仅在静态资源发生更改时刷新浏览器(并忽略代码中的任何更改)。 只需在项目中包含以下属性:
spring.devtools.remote.restart.enabled=false
在此之前,该插件默认支持资源热刷新,现在已被禁用,以支持上述解决方案。
您可以随时通过配置项目来恢复它:devtools
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<addResources>true</addResources>
</configuration>
</plugin>
</plugins>
</build>
启用后,运行应用程序时,任何目录都将添加到应用程序类路径中,并且将删除在类输出中找到的任何重复项。
这允许热刷新资源,这在开发 Web 应用程序时非常有用。
例如,您可以处理 HTML、CSS 或 JavaScript 文件,并立即查看更改,而无需重新编译应用程序。
这也是一种有用的方法,可以让您的前端开发人员无需下载和安装 Java IDE 即可工作。addResources
src/main/resources
使用此功能的副作用是在生成时筛选资源将不起作用。 |
为了与目标保持一致,目标以这样一种方式构建类路径,即插件配置中排除的任何依赖项也会从类路径中排除。
有关详细信息,请参阅专用示例。repackage
run
有时,运行应用程序的测试变体很有用。
例如,如果要在开发时使用 Testcontainers 或使用某些测试存根。
将目标与许多与此目的相同的功能和配置选项一起使用。test-run
run
使用此功能的副作用是在生成时筛选资源将不起作用。 |
spring-boot:run
org.springframework.boot:spring-boot-maven-plugin:3.3.2-SNAPSHOT
就地运行应用程序。
可选参数
名字 | 类型 | 违约 |
---|---|---|
|
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
|
|
|
||
|
|
|
|
||
|
|
|
|
参数详细信息
addResources
将 maven 资源直接添加到类路径中,这样就可以对资源进行实时就地编辑。重复的资源将被删除,以防止它们在被调用时出现两次。请考虑添加到您的项目中,因为它提供了此功能以及更多功能。target/classes
ClassLoader.getResources()
spring-boot-devtools
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
additionalClasspathElements
应添加到类路径的其他类路径元素。元素可以是包含类和资源的目录,也可以是 jar 文件。
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
classesDirectory
包含应用于运行应用程序的类和资源文件的目录。
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
commandlineArguments
应传递给应用程序的命令行中的参数。使用空格分隔多个参数,并确保在引号之间换行多个值。指定时,优先于 。#arguments
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
directories
包含应添加到类路径中的类或资源的其他目录。
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
environmentVariables
应与用于运行应用程序的分叉进程关联的环境变量列表。
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
excludeGroupIds
要排除的 groupId 名称的逗号分隔列表(完全匹配)。
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
excludes
要排除的项目定义的集合。该元素定义必需组件和组件以及可选组件。配置为属性时,值应以逗号分隔,并用冒号分隔的组件分隔:Exclude
groupId
artifactId
classifier
groupId:artifactId,groupId:artifactId:classifier
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
includes
要包含的项目定义的集合。该元素定义必需组件和组件以及可选组件。配置为属性时,值应以逗号分隔,并用冒号分隔的组件分隔:Include
groupId
artifactId
classifier
groupId:artifactId,groupId:artifactId:classifier
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
jvmArguments
应与用于运行应用程序的分叉进程相关联的 JVM 参数。在命令行中,确保在引号之间换行多个值。
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
mainClass
主类的名称。如果未指定,则将使用找到的第一个包含“main”方法的编译类。
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
optimizedLaunch
是否应该优化 JVM 的启动。
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
profiles
要激活的弹簧轮廓。指定“spring.profiles.active”参数的便捷快捷方式。在命令行上,使用逗号分隔多个配置文件。
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
systemPropertyVariables
要传递给进程的 JVM 系统属性列表。
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 | 类型 | 违约 |
---|---|---|
|
|
名字 | 类型 | 违约 |
---|---|---|
|
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
|
|
|
||
|
|
|
|
||
|
|
|
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
spring-boot:test-run
org.springframework.boot:spring-boot-maven-plugin:3.3.2-SNAPSHOT
使用测试运行时类路径就地运行应用程序。将用于启动应用程序的主类确定如下: 配置的主类(如果有)。然后在测试类目录中找到主类(如果有)。然后在 classes 目录中找到主类(如果有)。
可选参数
名字 | 类型 | 违约 |
---|---|---|
|
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
|
|
|
||
|
|
|
|
||
|
参数详细信息
addResources
将 maven 资源直接添加到类路径中,这样就可以对资源进行实时就地编辑。重复的资源将被删除,以防止它们在被调用时出现两次。请考虑添加到您的项目中,因为它提供了此功能以及更多功能。target/classes
ClassLoader.getResources()
spring-boot-devtools
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
additionalClasspathElements
应添加到类路径的其他类路径元素。元素可以是包含类和资源的目录,也可以是 jar 文件。
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
classesDirectory
包含应用于运行应用程序的类和资源文件的目录。
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
commandlineArguments
应传递给应用程序的命令行中的参数。使用空格分隔多个参数,并确保在引号之间换行多个值。指定时,优先于 。#arguments
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
directories
包含应添加到类路径中的类或资源的其他目录。
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
environmentVariables
应与用于运行应用程序的分叉进程关联的环境变量列表。
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
excludeGroupIds
要排除的 groupId 名称的逗号分隔列表(完全匹配)。
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
excludes
要排除的项目定义的集合。该元素定义必需组件和组件以及可选组件。配置为属性时,值应以逗号分隔,并用冒号分隔的组件分隔:Exclude
groupId
artifactId
classifier
groupId:artifactId,groupId:artifactId:classifier
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
includes
要包含的项目定义的集合。该元素定义必需组件和组件以及可选组件。配置为属性时,值应以逗号分隔,并用冒号分隔的组件分隔:Include
groupId
artifactId
classifier
groupId:artifactId,groupId:artifactId:classifier
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
jvmArguments
应与用于运行应用程序的分叉进程相关联的 JVM 参数。在命令行中,确保在引号之间换行多个值。
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
mainClass
主类的名称。如果未指定,则将使用找到的第一个包含“main”方法的编译类。
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
optimizedLaunch
是否应该优化 JVM 的启动。
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
profiles
要激活的弹簧轮廓。指定“spring.profiles.active”参数的便捷快捷方式。在命令行上,使用逗号分隔多个配置文件。
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
systemPropertyVariables
要传递给进程的 JVM 系统属性列表。
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 | 类型 | 违约 |
---|---|---|
|
|
|
|
|
名字 | 类型 | 违约 |
---|---|---|
|
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
|
|
|
||
|
|
|
|
||
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
名字 |
|
---|---|
类型 |
|
默认值 |
|
User 属性 |
|
因为 |
|
例子
调试应用程序
和 目标在分叉进程中运行应用程序。
如果需要调试它,则应添加必要的 JVM 参数以启用远程调试。
以下配置将暂停该进程,直到调试器已加入端口 5005:run
test-run
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>
-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005
</jvmArguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
也可以在命令行上指定这些参数:
$ mvn spring-boot:run -Dspring-boot.run.jvmArguments=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005
使用系统属性
可以使用该属性指定系统属性。
以下示例设置为 和 42:systemPropertyVariables
property1
test
property2
<project>
<build>
<properties>
<my.value>42</my.value>
</properties>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<property1>test</property1>
<property2>${my.value}</property2>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
如果值为空或未定义(即>),则使用空 String 作为值来设置系统属性。
Maven 修剪 pom 中指定的值,因此无法通过此机制指定需要以空格开头或结尾的 System 属性:请考虑改用。<my-property/
jvmArguments
任何 String 类型的 Maven 变量都可以作为系统属性传递。
任何传递任何其他 Maven 变量类型(例如 a 或 变量)的尝试都会导致变量表达式逐字逐句传递(未计算)。List
URL
该参数优先于使用上述机制定义的系统属性。
在以下示例中,的值为 :jvmArguments
property1
overridden
$ mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dproperty1=overridden"
使用环境变量
可以使用该属性指定环境变量。
以下示例设置 'ENV1', 'ENV2', 'ENV3', 'ENV4' 环境变量:environmentVariables
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<environmentVariables>
<ENV1>5000</ENV1>
<ENV2>Some Text</ENV2>
<ENV3/>
<ENV4></ENV4>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
如果值为空或未定义(即 >),则将 env 变量设置为空 String 作为值。
Maven 修剪 pom 中指定的值,因此无法指定需要以空格开头或结尾的 env 变量。<MY_ENV/
任何 String 类型的 Maven 变量都可以作为系统属性传递。
任何传递任何其他 Maven 变量类型(例如 a 或 变量)的尝试都会导致变量表达式逐字逐句传递(未计算)。List
URL
以这种方式定义的环境变量优先于现有值。
使用应用程序参数
可以使用该属性指定应用程序参数。
下面的示例设置两个参数: 和 :arguments
property1
property2=42
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<arguments>
<argument>property1</argument>
<argument>property2=${my.value}</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
在命令行上,参数以相同的方式用空格分隔。
如果参数包含空格,请确保用引号引号。
在以下示例中,有两个参数可用:和 :jvmArguments
property1
property2=Hello World
$ mvn spring-boot:run -Dspring-boot.run.arguments="property1 'property2=Hello World'"
指定活动配置文件
可以使用参数指定用于特定应用程序的活动配置文件。profiles
以下配置启用 and 配置文件:local
dev
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<profiles>
<profile>local</profile>
<profile>dev</profile>
</profiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
也可以在命令行上指定要启用的配置文件,请确保用逗号分隔它们,如以下示例所示:
$ mvn spring-boot:run -Dspring-boot.run.profiles=local,dev