spring-boot的三种启动方式
spring-boot的启动方式主要有三种:
1. 运行带有main方法类
2. 通过命令行 java -jar 的方式
3. 通过spring-boot-plugin的方式
一、执行带有main方法类
这种方式很简单,我主要是通过idea的方式,进行执行。这种方式在启动的时候,会去自动加载classpath下的配置文件
(这里只是单独的强调了classpath下,其实spring-boot有自己的加载路径和优先级的,日后在发布).
@RestController
@EnableAutoConfiguration
public class Example {
@RequestMapping("/")
public String home() {
return "Hello World";
}
public static void main(String[] args) {
/**
* SpringApplication会自动加载application.properties文件,具体的加载路径包含以下:
* <p>
* 1. A <b>/config</b> subdirectory of the current directory;
* <p/>
* <p>
* 2. The Current Directory
* </p>
* <p>
* 3. A classpath /config package
* </p>
* <p>
* 4. The classpath root.
* </p>
*/
SpringApplication.run(Example.class, args);
}
}
在idea中,可以通过配置application的方式配置上自己请求参数

二、通过java -jar的方式
java -jar jar_path --param
jar_path: 指代将项目打包为jar打包之后的存储路径
--param: 为需要在命令行指定的参数。例如:
java -jar emample.jar --server.port=8081
该命令通过在启动行指定了项目启动后绑定的端口号,因为该命令行参数,将会覆盖application.properties中的端口配置
三、通过spring-boot-plugin方式启动
如果需要正常使用该maven查件,需要我们在maven项目中增加以下插件配置:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!--<version>${spring.boot.version}</version>-->
<!--<executions>-->
<!--<execution>-->
<!--<goals>-->
<!--<goal>repackage</goal>-->
<!--</goals>-->
<!--</execution>-->
<!--</executions>-->
</plugin>
注: 因为我在项目中指定了父模块 spring-boot-starter-parent。因此我不需要单独指定插件版本,该父模块会自动匹配与当前spring-boot版本相匹配的查件版本。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<!--<groupId>com.spring.sourcecode</groupId>-->
<!--<artifactId>learn.spring</artifactId>-->
<!--<version>1.0-SNAPSHOT</version>-->
</parent>
准备工作做好之后,我们需要进入项目的根目录,执行
mvn sprint-boot:run
该命令能够正常启动项目,但是如何为其指定执行参数呢?
spring-boot:run该maven查件在插件首页中指定了相关能够使用的可选参数:
通过查阅文档,可以通过命令的方式查看具体选项的意义以及用法:
mvn spring-boot:help -Ddetail

其中arguments的描述中,大意为:指定的参数会传递给具体应用,如果有多个参数需要指定,以","进行分割。具体用法通过run.arguments来指定:
mvn spring-boot:run -Drun.arguments="--server.port=8888"
以上就是三种启动方式的描述
————————————————
版权声明:本文为CSDN博主「专注着」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u011425751/article/details/79507386
spring-boot的三种启动方式的更多相关文章
- Spring Boot 项目几种启动方式
Spring Boot 项目几种启动方式 1. 使用 main 启动 jar xxxx.jar 2. 使用 mvn 启动 mvn spring-boot:run 3. 使用 Spring Boot c ...
- Spring boot 集成三种定时任务方式
三种定时任务方式分别为 org.springframework.scheduling.annotation.Scheduled java.util.concurrent.ScheduledExecut ...
- Spring boot 集成三种拦截方式
三种拦截方式分别为: javax.servlet.Filter org.springframework.web.servlet.HandlerInterceptor org.aspectj.lang. ...
- spring-boot的三种启动方式[z]
https://blog.csdn.net/u011425751/article/details/79507386 有段时间没有写博客了,也在努力的从传统单机开发向分布式系统过度,所以再次做一些笔记, ...
- spring Bean的三种配置方式
Spring Bean有三种配置方式: 传统的XML配置方式 基于注解的配置 基于类的Java Config 添加spring的maven repository <dependency> ...
- Spring IOC以及三种注入方式
IOC是spring的最基础部分,也是核心模块,Spring的其他组件模块和应用开发都是以它为基础的.IOC把spring的面向接口编程和松耦合的思想体现的淋漓尽致. IOC概念 IOC(Invers ...
- Spring IOC 中三种注入方式
项目错误知识点记录 正文 最近在项目的时候,用到Spring框架,Spring框架提供了一种IOC的自动注入功能,可以很轻松的帮助我们创建一个Bean,这样就省的我们四处写new Object()这样 ...
- Spring:Spring-IOC三种注入方式、注入不同数据类型
一.Spring IOC(依赖注入的三种方式): 1.Setter方法注入 package com.jpeony.spring.setter; import com.jpeony.spring.com ...
- Spring Boot项目的不同启动方式
方式一: 直接通过IntelliJ IDEA启动,直接执行Spring Boot项目的main()方法. 方法二: 将项目打包成jar包,首先需要在pom.xml文件的根节点下添加如下配置: < ...
随机推荐
- apache2_fastcgi_python
1. 前言 之前有用的是apache2 + python + jon模块下的cgi, fcgi. 该框架搭建的服务器我没有找到能够让python程序持久运行的方法(作为一个服务). 最近看了篇文档, ...
- table表格整体居中 和 table表格中各行各列内容居中
1.table表格整个居中<div style="text-align: center;"> <table border="1" style= ...
- java 序列化和反序列化的底层实现原理
出处:序列化和反序列化的底层实现原理是什么? 一.基本概念1.什么是序列化和反序列化 (1)Java序列化是指把Java对象转换为字节序列的过程,而Java反序列化是指把字节序列恢复为Java对象的过 ...
- 华为设备ACL与NAT技术
ACL 访问控制列表(Access Control Lists),是应用在路由器(或三层交换机)接口上的指令列表,用来告诉路由器哪些数据可以接收,哪些数据是需要被拒绝的,ACL的定义是基于协议的,它适 ...
- ubuntu下npm全局安装包报错的解决方案
大概就是 npm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning ERR ...
- Fix Scheduled Task Won’t Run for .BAT File
Step 1: Check File/Folder Permissions The first step to fixing this issue is ensuring that the accou ...
- Qt 中使用Java代码获取安卓设备的MAC地址(安卓9.0)
public String GetDeviceMAC() { String strMacAddr = null; try { // 获得IpD地址 InetAddress ip = getLocalI ...
- 数据库HAVING的使用
HAVING语句通常与GROUP BY语句联合使用,用来过滤由GROUP BY语句返回的记录集. HAVING语句的存在弥补了WHERE关键字不能与聚合函数联合使用的不足. 记录一下
- java启动server时报端口无效解决方法
今天在Java里配置Tomcat服务器,启动时出现如下图报错信息 The server cannot be started because one or more of the ports are i ...
- Redis之淘汰策略
Redis 内存数据集大小上升到一定大小的时候,就会进行数据淘汰策略. Redis 提供了 6 种数据淘汰策略: 1. volatile-lru:从已设置过期时间的数据集中挑选最近最少使用的数据淘汰. ...