背景:有时候在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
至此,三种启动方式完毕