| 名称 | 链接 | 备注 |
| :-- | :-- | :-- |
| 项目主页 | https://github.com/zq2599/blog_demos | 该项目在GitHub上的主页 |
| git仓库地址(https) | https://github.com/zq2599/blog_demos.git | 该项目源码的仓库地址,https协议 |
| git仓库地址(ssh) | git@github.com:zq2599/blog_demos.git | 该项目源码的仓库地址,ssh协议 |
这个git项目中有多个文件夹,本章的源码在hellojib文件夹下,如下图红框所示:
准备java应用
准备一个最简单的springboot应用hellojib,用于实战构建docker镜像;
- 该应用是基于maven构建的,启动类如下:
package com.bolingcavalry.hellojib;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class HellojibApplication {
public static void main(String[] args) {
SpringApplication.run(HellojibApplication.class, args);
}
}
- 有一个controller用于后面验证服务是否正常:
package com.bolingcavalry.hellojib.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
-
@Description: 普通的controller
-
@author: willzhao E-mail: zq2599@gmail.com
-
@date: 2019/6/29 20:21
*/
@RestController
public class HelloController {
@RequestMapping(“/hello”)
public String hello(){
return "Hello, " + new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”).format(new Date());
}
}
- 最重要的部分来了,pom.xml的内容如下,请注意注释:
<project xmlns=“http://maven.apache.org/POM/4.0.0” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=“http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”>
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.1.6.RELEASE
com.bolingcavalry
hellojib
0.0.1-SNAPSHOT
hellojib
Demo project for Spring Boot
<java.version>1.8</java.version>
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-maven-plugin
com.google.cloud.tools
jib-maven-plugin
1.3.0
openjdk:8-jdk-stretch
bolingc