https://blog.csdn.net/u011425751/article/details/79507386

有段时间没有写博客了,也在努力的从传统单机开发向分布式系统过度,所以再次做一些笔记,以方便日后查看。

直接进入正题吧,今天记录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
原文:https://blog.csdn.net/u011425751/article/details/79507386
版权声明:本文为博主原创文章,转载请附上博文链接!

spring-boot的三种启动方式[z]的更多相关文章

  1. Spring Boot 项目几种启动方式

    Spring Boot 项目几种启动方式 1. 使用 main 启动 jar xxxx.jar 2. 使用 mvn 启动 mvn spring-boot:run 3. 使用 Spring Boot c ...

  2. Spring boot 集成三种定时任务方式

    三种定时任务方式分别为 org.springframework.scheduling.annotation.Scheduled java.util.concurrent.ScheduledExecut ...

  3. Spring boot 集成三种拦截方式

    三种拦截方式分别为: javax.servlet.Filter org.springframework.web.servlet.HandlerInterceptor org.aspectj.lang. ...

  4. spring-boot的三种启动方式

    spring-boot的启动方式主要有三种: 1. 运行带有main方法类 2. 通过命令行 java -jar 的方式 3. 通过spring-boot-plugin的方式 一.执行带有main方法 ...

  5. spring Bean的三种配置方式

    Spring Bean有三种配置方式: 传统的XML配置方式 基于注解的配置 基于类的Java Config 添加spring的maven repository <dependency> ...

  6. Spring IOC以及三种注入方式

    IOC是spring的最基础部分,也是核心模块,Spring的其他组件模块和应用开发都是以它为基础的.IOC把spring的面向接口编程和松耦合的思想体现的淋漓尽致. IOC概念 IOC(Invers ...

  7. Spring IOC 中三种注入方式

    项目错误知识点记录 正文 最近在项目的时候,用到Spring框架,Spring框架提供了一种IOC的自动注入功能,可以很轻松的帮助我们创建一个Bean,这样就省的我们四处写new Object()这样 ...

  8. Spring:Spring-IOC三种注入方式、注入不同数据类型

    一.Spring IOC(依赖注入的三种方式): 1.Setter方法注入 package com.jpeony.spring.setter; import com.jpeony.spring.com ...

  9. Spring Boot项目的不同启动方式

    方式一: 直接通过IntelliJ IDEA启动,直接执行Spring Boot项目的main()方法. 方法二: 将项目打包成jar包,首先需要在pom.xml文件的根节点下添加如下配置: < ...

随机推荐

  1. 从gitlab或者github采用git clone和download zip的区别

    不要做伸手党啊大兄弟,这种问题自己稍加理解就知道答案了,实在想不到就上谷歌搜一下嘛,比如这个:git - Github: difference between Clone in desktop and ...

  2. 第2章 Java基本语法(上): 变量与运算符

    2-1 关键字与保留字 关键字(keyword) 保留字(reserved word) 2-2 标识符(Identifier) 案例 class Test{ public static void ma ...

  3. OpenLDAP主从

    yum -y install compat-openldap必须得安装这个   1:在主上       备份         cp /etc/openldap/slapd.conf /etc/open ...

  4. JavaBean是什么,POJO是什么

    参考:https://stackoverflow.com/questions/3295496/what-is-a-javabean-exactly https://stackoverflow.com/ ...

  5. 自己动手,丰衣足食!Python3网络爬虫实战案例

    本教程是崔大大的爬虫实战教程的笔记:网易云课堂 Python3+Pip环境配置 Windows下安装Python: http://www.cnblogs.com/0bug/p/8228378.html ...

  6. 报错:org.apache.hadoop.hive.metastore.HiveMetaException: Failed to get schema version.

    报错环境: CDH中集成的hive服务,启动报错,所以初始化一下元数据. 配置文件:/etc/hive/conf hive-site.xml 命令目录:/opt/cloudera/parcels/CD ...

  7. The perception and large margin classifiers

    假设样例按照到来的先后顺序依次定义为.为样本特征,为类别标签.任务是到来一个样例,给出其类别结果的预测值,之后我们会看到真实值,然后根据真实值来重新调整模型参数,整个过程是重复迭代的过程,直到所有的样 ...

  8. ssl协议相关

    <1> SSL版本 测试浏览器支持的SSL版本的网站: https://www.ssllabs.com/ssltest/viewMyClient.html 0xfefd    (DTLS ...

  9. Vue 双向数据绑定、事件介绍以及ref获取dom节点

    vue是一个MVVM的框架 M model V view MVVM  model改变会影响视图view,view改变会影响model 双向数据绑定必须在表单里面使用 //我发现在谷歌浏览器翻译后的网页 ...

  10. Android Studio计时跳转或点击跳转至主页面

    这个总体来说是比较简单的,计时跳转一般调用Android Studio中的Handler方法. 一.发生点击事件跳转页面 mBtnTextView = (Button) findViewById(R. ...