Skip to content

spring boot

Posted on:December 7, 2022 at 11:18 PM

背景

需要做到以下几步:

开始

下载spring boot demo ,链接在

https://start.spring.io/

spring boot download

一个可用的例子

https://start.spring.io/#!type=maven-project&language=java&platformVersion=3.0.0&packaging=jar&jvmVersion=17&groupId=com.example&artifactId=demo&name=demo&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.demo

解压

然后下载下来名字叫demo.zip, 然后需要解压

unzip  demo.zip 

安装maven

maven 是java的一个包管理工具

对于ubuntu 来说 ,使用下面的命令安装maven

sudo apt install maven

添加tomcat

pom.xml 添加tomcat相关内容

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

编译成一个fatjar

使用命令 mvn spring-boot:repackage 编译成一个fat-jar

mvn package

启动jar包

命令为java -jar ./target/demo-0.0.1-SNAPSHOT.jar

$ java -jar ./target/demo-0.0.1-SNAPSHOT.jar 

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.0.0)

2022-12-09T00:43:52.343+08:00  INFO 1459280 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication v0.0.1-SNAPSHOT using Java 17.0.5 with PID 1459280 (/home/dai/spring/demo/target/demo-0.0.1-SNAPSHOT.jar started by dai in /home/dai/spring/demo)
2022-12-09T00:43:52.346+08:00  INFO 1459280 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to 1 default profile: "default"
2022-12-09T00:43:53.153+08:00  INFO 1459280 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2022-12-09T00:43:53.162+08:00  INFO 1459280 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-12-09T00:43:53.163+08:00  INFO 1459280 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.1]
2022-12-09T00:43:53.232+08:00  INFO 1459280 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-12-09T00:43:53.234+08:00  INFO 1459280 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 835 ms
2022-12-09T00:43:53.537+08:00  INFO 1459280 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2022-12-09T00:43:53.549+08:00  INFO 1459280 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 1.522 seconds (process running for 1.859)

相关阅读