简介

  Spring Boot Maven Plugin插件提供spring boot在maven中的支持。允许你打包可运行的jar包或war包。

  插件提供了几个maven目标和Spring Boot 应用一起工作。总的有:

  run: 这个目标和直接java -jar 来启动基本相同,唯一不同的是java -jar需要打包后才能跑,而run目标不需要。这个当程序编译打包需要比较长时间时,用run目标来跑可以节约时间。

一、简单使用

  Spring Boot Maven Plugin 包括一个 run 目标,该目标被用于从命令行启动你的应用程序。比如:

 mvn spring-boot:run 

  eclipse用法如下:

  

  启动后的日志:

 [INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building springboot 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:1.5.6.RELEASE:run (default-cli) > test-compile @ springboot >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ springboot ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ springboot ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ springboot ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ springboot ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< spring-boot-maven-plugin:1.5.6.RELEASE:run (default-cli) < test-compile @ springboot <<<
[INFO]
[INFO]
[INFO] --- spring-boot-maven-plugin:1.5.6.RELEASE:run (default-cli) @ springboot ---
[INFO] Downloading: http://maven.aliyun.com/nexus/content/groups/public/org/springframework/boot/spring-boot-loader-tools/1.5.6.RELEASE/spring-boot-loader-tools-1.5.6.RELEASE.pom
[INFO] Downloaded: http://maven.aliyun.com/nexus/content/groups/public/org/springframework/boot/spring-boot-loader-tools/1.5.6.RELEASE/spring-boot-loader-tools-1.5.6.RELEASE.pom (3.8 kB at 5.0 kB/s)
[INFO] Downloading: http://maven.aliyun.com/nexus/content/groups/public/org/springframework/boot/spring-boot-loader-tools/1.5.6.RELEASE/spring-boot-loader-tools-1.5.6.RELEASE.jar
[INFO] Downloaded: http://maven.aliyun.com/nexus/content/groups/public/org/springframework/boot/spring-boot-loader-tools/1.5.6.RELEASE/spring-boot-loader-tools-1.5.6.RELEASE.jar (151 kB at 107 kB/s) . ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.6.RELEASE) 2017-09-16 16:15:53.173 INFO 6900 --- [ main] c.p.springboot.SpringbootApplication : Starting SpringbootApplication on pc-PC with PID 6900 (D:\qinxiong\workspaceSpring\springboot\target\classes started by Administrator in D:\qinxiong\workspaceSpring\springboot)
2017-09-16 16:15:53.173 INFO 6900 --- [ main] c.p.springboot.SpringbootApplication : No active profile set, falling back to default profiles: default
2017-09-16 16:15:53.204 INFO 6900 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2689929b: startup date [Sat Sep 16 16:15:53 CST 2017]; root of context hierarchy
2017-09-16 16:15:54.668 INFO 6900 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-09-16 16:15:54.683 INFO 6900 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2017-09-16 16:15:54.683 INFO 6900 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.16
2017-09-16 16:15:54.762 INFO 6900 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-09-16 16:15:54.762 INFO 6900 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1558 ms
2017-09-16 16:15:54.918 INFO 6900 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-09-16 16:15:54.918 INFO 6900 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-09-16 16:15:54.918 INFO 6900 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-09-16 16:15:54.918 INFO 6900 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-09-16 16:15:54.918 INFO 6900 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-09-16 16:15:55.168 INFO 6900 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2689929b: startup date [Sat Sep 16 16:15:53 CST 2017]; root of context hierarchy
2017-09-16 16:15:55.230 INFO 6900 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hello]}" onto public java.lang.String com.pitaya.springboot.HelloController.index()
2017-09-16 16:15:55.230 INFO 6900 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-09-16 16:15:55.230 INFO 6900 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-09-16 16:15:55.246 INFO 6900 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-09-16 16:15:55.246 INFO 6900 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-09-16 16:15:55.293 INFO 6900 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-09-16 16:15:55.404 INFO 6900 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-09-16 16:15:55.466 INFO 6900 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-09-16 16:15:55.466 INFO 6900 --- [ main] c.p.springboot.SpringbootApplication : Started SpringbootApplication in 2.637 seconds (JVM running for 8.001)

run目标的日志

二、实战

  默认情况下,应用程序直接从Maven JVM执行。 如果您需要在分叉进程(maven进程fork出来的子进程)中运行,可以使用'fork'选项。 如果指定了'jvmArguments'或'agent'选项,或者如果存在devtools,应用程序也会在分叉进程执行。

  如果需要指定一些JVM参数(即用于调试目的),可以使用jvmArguments参数,请看下面实例:

 <project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.7.RELEASE</version>
<configuration>
<jvmArguments>
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
</jvmArguments>
</configuration>
...
</plugin>
...
</plugins>
...
</build>
...
</project>

插件使用jvmArguments

  请注意,由于您指定了一些JVM参数,所以该应用是自动在分叉进程中运行。这些参数也可以在命令行中指定,具体如下:

mvn spring-boot:run -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

命令行指定jvm参数

  当我们程序中设置了多个profile的yml文件,比如application.yml,application-dev.yml,application-test.yml,application-prd.yml。我们可以通过设置profiles参数来指定应用程序的active的profile。下面的例子演示指定要application.yml和application-test.yml两个文件。具体如下:

<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.7.RELEASE</version>
<configuration>
<profiles>
<profile>test</profile>
</profiles>
</configuration>
...
</plugin>
...
</plugins>
...
</build>
...
</project>

插件使用profile

  如果要多加一个profile,只要多添加<profile>prd</profile>即可。

  同样的,要启动的profiles也可以通过命令行来指定,需要使用多个profile时,用逗号隔开,具体如下:

 mvn spring-boot:run -Drun.profiles=test,prd

命令行指定profile

喜欢请微信扫描下面二维码,关注我公众号--“精修Java”,做一些实战项目中的问题和解决方案分享。

Spring cloud的Maven插件(二):run目标的更多相关文章

  1. Spring cloud的Maven插件(一):repackage目标

    简介 Spring Boot Maven Plugin插件提供spring boot在maven中的支持.允许你打包可运行的jar包或war包. 插件提供了几个maven目标和Spring Boot ...

  2. Spring Boot的Maven插件Spring Boot Maven plugin详解

    Spring Boot的Maven插件(Spring Boot Maven plugin)能够以Maven的方式为应用提供Spring Boot的支持,即为Spring Boot应用提供了执行Mave ...

  3. spring cloud微服务实践二

    在上一篇,我们已经搭建了spring cloud微服务中的注册中心.但只有一个注册中心还远远不够. 接下来我们就来尝试提供服务. 注:这一个系列的开发环境版本为 java1.8, spring boo ...

  4. Spring Cloud gateway 网关服务二 断言、过滤器

    微服务当前这么火爆的程度,如果不能学会一种微服务框架技术.怎么能升职加薪,增加简历的筹码?spring cloud 和 Dubbo 需要单独学习.说没有时间?没有精力?要学俩个框架?而Spring C ...

  5. 《Spring Cloud》学习(二) 负载均衡!

    第二章 负载均衡 负载均衡是对系统的高可用.网络压力的缓解和处理能力扩容的重要手段之一.Spring Cloud Ribbon是一个基于 HTTP 和 TCP 的客户端负载均衡工具,它基于Netfli ...

  6. Spring Cloud 网关服务 zuul 二

    有一点上篇文章忘了 讲述,nacos的加载优先级别最高.服务启动优先拉去配置信息.所以上一篇服务搭建我没有讲述在nacos 中心创建的配置文件 可以看到服务端口和注册中心都在配置文件中配置化 属性信息 ...

  7. Spring Cloud进阶之路 | 二:服务提供者(discovery)

    1 创建父项目 以前文所述,以spring boot 2.1.7.RELEASE为基,spring cloud版本为Greenwich.SR2,spring cloud alibaba版本为2.1.0 ...

  8. Spring Cloud 学习笔记(二)——Netflix

    4 Spring Cloud Netflix Spring Cloud 通过自动配置和绑定到Spring环境和其他Spring编程模型惯例,为Spring Boot应用程序提供Netflix OSS集 ...

  9. Spring Cloud Stream教程(二)主要概念

    Spring Cloud Stream提供了一些简化了消息驱动的微服务应用程序编写的抽象和原语.本节概述了以下内容: Spring Cloud Stream的应用模型 Binder抽象 持续的发布 - ...

随机推荐

  1. 20155326 实验四 Android程序设计实验报告

    20155326 实验四 Android程序设计实验报告 实验内容 1.基于Android Studio开发简单的Android应用并部署测试; 2.了解Android.组件.布局管理器的使用: 3. ...

  2. ScheduledExecutorService的使用

    http://407827531.iteye.com/blog/1329597 ScheduledExecutorService接口 在ExecutorService的基础上,ScheduledExe ...

  3. FPGA&ASIC基本开发流程

    FPGA&数字IC笔面试常考系列 题目:简述ASIC设计流程,并列举出各部分用到的工具. ASIC开发基本流程 芯片架构,考虑芯片定义.工艺.封装 RTL设计,使用Verilog.System ...

  4. 取得cxgrid的表格的值,仔细看下面的代码

    procedure TfrmMain.cxGridDBTableView_List_PSSJCustomDrawCell(Sender: TcxCustomGridTableView; ACanvas ...

  5. jsp中文乱码解决办法

    一.JSP页面显示乱码 二.表单提交中文时出现乱码 三.数据库连接 大家在JSP的开发过程中,经常出现中文乱码的问题,可能一至困扰着您,我现在把我在JSP开发中遇到 的中文乱码的问题及解决办法写出来供 ...

  6. winform最小化后重复进load事件原因

    最近编写一个工具发现的问题,窗体不论是最小化还是进入托盘,重新打开的时候都会进入控件load事件. 产生这个现象的条件是: 1.使用了用户控件,在控件中使用了load事件 2.在主窗体中,隐藏或显示任 ...

  7. 解决C#项目出现“此项目引用这台计算机上缺少的 NuGet 程序包。使用 NuGet 程序包还原可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 ..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props”

    1.打开项目的.csproj文件 2.删掉如下选中的内容: 3.右键项目-->管理NuGet程序包(N) 找到Microsoft.CodeDom.Providers.DotNetCompiler ...

  8. Lerning Entity Framework 6 ------ Defining Relationships

    There are three types of relationships in database. They are: One-to-Many One-to-One Many-to-Many Th ...

  9. Linux Compile Multiple C++ Files

    Compile Two Files: $ CC -c Main.cc Sales_item.cc # by default generates a.exe # some compilers gener ...

  10. UCore-Lab1

      日期:2019/3/31 内容:makefile分析: 一."Makefile"分析 1.1 ucore.img lab1已有的源文件 目录 文件 boot asm.h.boo ...