本篇文章给大家分享的是有关怎么在码头工人中部署一个Spring-boot项目,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
, <强> 1.1快速启动砰的一声。xml加入如下依赖强>
& lt; parent> ,,,& lt; groupId> org.springframework.boot ,,,& lt; artifactId> spring-boot-starter-parent ,,,& lt; version> 2.0.5.RELEASE & lt;才能/parent> & lt;才能properties> ,,,& lt; java.version> 1.8 & lt;/java.version> ,,,& lt; project.build.sourceEncoding> UTF-8 & lt;才能/properties> & lt;才能dependencies> ,,,& lt; dependency> ,,,,,& lt; groupId> org.springframework.boot ,,,,,& lt; artifactId> spring-boot-starter-web ,,,& lt;/dependency> ,,,& lt; dependency> ,,,,,& lt; groupId> org.springframework.boot ,,,,,& lt; artifactId> spring-boot-starter-test ,,,,,& lt; scope> test ,,,& lt;/dependency> & lt;才能/dependencies> & lt;才能build> ,,,& lt; finalName> spring-docker ,,,& lt; plugins> ,,,,,& lt; plugin> ,,,,,,,& lt; groupId> org.springframework.boot ,,,,,,,& lt; artifactId> spring-boot-maven-plugin ,,,,,& lt;/plugin> ,,,& lt;/plugins> & lt;才能/build>
Spring-boot启动类
@SpringBootApplication public class  DockerApplication { public 才能;static  void main (String [], args), { ,,,SpringApplication.run (DockerApplication.class, args); ,,} }
测试API
@RestController public class  DockerStarterApi { @GetMapping才能(“/api/码头工人/hello") public 才能;String  hello (), { ,,,return “hello docker"; ,,} }
配置启动配置文件<代码>应用程序。yml 代码>
服务器: ,端口:9090,#,为了展示效果,,这里改了默认端口8080
检查弹簧启动
只,____ ,,,, _ ,,,,, __ _ _ ,/\ \/,___ # 39;_ __ _ _ (_) _ __ __ _ \, \ \, \ (,(,)\ ___ |, & # 39; _ |, & # 39; _ |, |, & # 39; _ \/, _”, | \ \祝福;\,\ ,\ \/___)|,| _)|,|,|,|,|,| |,(_ |,|,),),,) & # 39;大敌;__ | |,.__ | _ |,| _ | _ |,| _ \ __,|,/,/,/,/,=========| _ |==============| ___/=/_/_/_/,::Spring Boot ::,,,, (v2.0.2.RELEASE) … 2018 - 12 - 17,17:26:13.385 INFO 48740,——安康;(,,,,,主要],o.s.j.e.a.AnnotationMBeanExporter ,,,:, Registering beans for JMX exposure 提醒启动 2018 - 12 - 17,17:26:13.448 INFO 48740,——安康;(,,,,,主要],o.s.b.w.embedded.tomcat.TomcatWebServer :, Tomcat started 提醒端口(s):, 9090, (http), with context path & # 39; & # 39; 2018 - 12 - 17,17:26:13.453 INFO 48740,——安康;(,,,,,主要],pers.study.docker.DockerApplication ,,:, Started DockerApplication 1.982,拷贝seconds (JVM running for 2.602)
检查API是否生效
,美元curl -XGET & # 39; http://localhost: 9090/API/码头工人/你好# 39; hello 码头工人
浏览器检查
<代码> http://localhost: 9090/api/码头工人/你好代码>
<强> 1.2打包启动强>
项目打包
完成上面步骤之后,执行打包命令:
,美元mvn clean -U -Dmaven.test.skip compile 包
因为上面的pom文件里面定义了<代码> finalName> 代码,所以在这里会看到编译打包之后<代码> 代码>目标目录下会生成<代码> spring-docker。jar 代码>
& lt; finalName> spring-docker
测试运行
,美元java -jar 目标/spring-docker.jar
不出意外(有问题留言~)运行结果同上并检查API是否生效即可。null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null