发布项目
第一步、创建项目
-
创建springboot项目
如何创建springboot项目,请见IDEA构建Springboot项目 -
编写HelloController
package com.demo.springinithello01.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello(){
System.out.println("hello 被访问了");
return "hello world";
}
}

3. 启动运行测试 http://localhost:8080/hello

第二步、手动发布到服务器
- 编写Dockerfile
FROM java:8
# 服务器只有dockerfile和jar在同级目录
COPY *.jar /app.jar
CMD ["--server.port=8080"]
# 对外端口
EXPOSE 8080
CMD echo "----app start---"
ENTRYPOINT ["java","-jar","/app.jar"]

2. 打包项目

3. 将jar和Dockerfile上传到服务器

4. 启动项目
#构建进行(在Dockerfile同目录下)
docker build -t springinit01 .
#启动项目
docker run -d -p 18080:8080 --name test-springinit springinit01


- 测试访问 http://106.13.2.249:18080/hello











