springboot的三种启动方式

背景:有时候在idea启动springboot会莫名的失败,那我们是不是要知道其它启动方式
目的:学习springboot
组网图:不涉及
工具:java version “1.8.0_65” ;Apache Maven 3.6.3;IDEA版本 2018.3 (准备步骤见本人其它博文)
步骤:
方法一:
使用idea启动
在这里插入图片描述
方法二:
在工程中shift+右键,在此处打开命令窗口
在这里插入图片描述
输入:mvn spring-boot:run

C:\Users\Administrator\Desktop\myfirst>mvn spring-boot:run
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< com.hua:myfirst >---------------------------
[INFO] Building myfirst 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.1.3.RELEASE:run (default-cli) > test-compi
le @ myfirst >>>
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ myfirst
---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ myfirst ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @
myfirst ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Administrator\Desktop\myfirs
t\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ myfir
st ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< spring-boot-maven-plugin:2.1.3.RELEASE:run (default-cli) < test-compi
le @ myfirst <<<
[INFO]
[INFO]
[INFO] --- spring-boot-maven-plugin:2.1.3.RELEASE:run (default-cli) @ myfirst --
-

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.3.RELEASE)

2020-02-12 20:33:55.812  INFO 7316 --- [           main] com.hua.myfirst.Myfirst
Application       : Starting MyfirstApplication on PC-20180516QJKJ with PID 7316
 (C:\Users\Administrator\Desktop\myfirst\target\classes started by Administrator
 in C:\Users\Administrator\Desktop\myfirst)
2020-02-12 20:33:55.817  INFO 7316 --- [           main] com.hua.myfirst.Myfirst
Application       : No active profile set, falling back to default profiles: def
ault
2020-02-12 20:33:57.406  INFO 7316 --- [           main] o.s.b.w.embedded.tomcat
.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-02-12 20:33:57.437  INFO 7316 --- [           main] o.apache.catalina.core.
StandardService   : Starting service [Tomcat]
2020-02-12 20:33:57.438  INFO 7316 --- [           main] org.apache.catalina.cor
e.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.16]
2020-02-12 20:33:57.456  INFO 7316 --- [           main] o.a.catalina.core.AprLi
fecycleListener   : The APR based Apache Tomcat Native library which allows opti
mal performance in production environments was not found on the java.library.pat
h: [C:\Program Files\Java\jdk1.8.0_65\bin;C:\Windows\Sun\Java\bin;C:\Windows\sys
tem32;C:\Windows;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Wind
ows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Pyth
on34;C:\Python34\Scripts;C:\strawberry\c\bin;C:\strawberry\perl\bin;C:\Program F
iles\Java\jdk1.8.0_65\bin;C:\Program Files\Java\jdk1.8.0_65\lib;D:\mysql-5.7.25-
winx64\bin;D:\apache-maven-3.6.3\bin;.]
2020-02-12 20:33:57.582  INFO 7316 --- [           main] o.a.c.c.C.[Tomcat].[loc
alhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-02-12 20:33:57.583  INFO 7316 --- [           main] o.s.web.context.Context
Loader            : Root WebApplicationContext: initialization completed in 1702
 ms
2020-02-12 20:33:57.871  INFO 7316 --- [           main] o.s.s.concurrent.Thread
PoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-02-12 20:33:58.124  INFO 7316 --- [           main] o.s.b.w.embedded.tomcat
.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2020-02-12 20:33:58.129  INFO 7316 --- [           main] com.hua.myfirst.Myfirst
Application       : Started MyfirstApplication in 2.744 seconds (JVM running for
 6.473)
2020-02-12 20:34:07.310  INFO 7316 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[loc
alhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-02-12 20:34:07.310  INFO 7316 --- [nio-8080-exec-1] o.s.web.servlet.Dispatc
herServlet        : Initializing Servlet 'dispatcherServlet'
2020-02-12 20:34:07.330  INFO 7316 --- [nio-8080-exec-1] o.s.web.servlet.Dispatc
herServlet        : Completed initialization in 20 ms

打开链接:http://127.0.0.1:8080/hello 结束请Ctrl+C
在这里插入图片描述

方法三:
项目部署方式,在工程中shift+右键,在此处打开命令窗口,执行:mvn clean package
但是报错了,[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.
22.1:test (default-test) on poject myfirst: There are test failures.,
应该是执行测试的时候失败了

在这里插入图片描述
解决方法有二:
一种是打包时跳过测试哪里
执行:mvn clean package -Dmaven.test.skip=true
在这里插入图片描述
在这里插入图片描述
另一种:在pom.xml加入如下内容,再执行:mvn clean package
在这里插入图片描述

<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>2.4.2</version>
				<configuration>
					<skipTests>true</skipTests>
				</configuration>
			</plugin>

在这里插入图片描述
然后我们再target目录就回发现多了jar包
在这里插入图片描述
然后在命令窗执行下面命令:java -jar target/myfirst-0.0.1-SNAPSHOT.jar
在这里插入图片描述
启动成功,打开链接:http://127.0.0.1:8080/hello
在这里插入图片描述
至此,三种启动方式完毕

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值