fix: java 示例改用自建 runtime-tomcat10;war 补录 Jackson 依赖,jar 去掉错误的 RuntimeInfo 抽象
This commit is contained in:
@@ -17,8 +17,7 @@ springboot-jar17/
|
||||
├── src/main/java/cn/odboy/demo/
|
||||
│ ├── DemoApplication.java # @SpringBootApplication 入口
|
||||
│ ├── DemoController.java # @RestController:/ 、/api/info、/api/hello/{name}
|
||||
│ ├── PageController.java # @Controller:/page 渲染 Thymeleaf 模板
|
||||
│ └── BootRuntimeInfo.java # 输出 Spring Boot 版本号与主机名
|
||||
│ └── PageController.java # @Controller:/page 渲染 Thymeleaf 模板
|
||||
├── src/main/resources/
|
||||
│ ├── application.yml # 端口 8084、优雅停机、actuator 只开 health
|
||||
│ └── templates/index.html # /page 页面
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package cn.odboy.demo;
|
||||
|
||||
import org.springframework.boot.SpringBootVersion;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Boot 环境下的版本信息实现。
|
||||
*/
|
||||
@Component
|
||||
public class BootRuntimeInfo implements DemoController.RuntimeInfo {
|
||||
|
||||
@Override
|
||||
public String appVersion() {
|
||||
return "Spring Boot " + SpringBootVersion.getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String hostname() {
|
||||
return RuntimeInfo.hostnameOrUnknown();
|
||||
}
|
||||
}
|
||||
@@ -9,16 +9,15 @@ import java.time.format.DateTimeFormatter;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.SpringVersion;
|
||||
import org.springframework.boot.SpringBootVersion;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 运行时信息接口,用于确认镜像里的 JDK / 时区 / 端口等是否符合预期。
|
||||
* 宿主 Profile(含 Boot 版本)通过构造注入,非 Boot 环境传空即可。
|
||||
*/
|
||||
@RestController
|
||||
public class DemoController {
|
||||
@@ -26,12 +25,6 @@ public class DemoController {
|
||||
private static final ZoneId TZ8 = ZoneId.of("Asia/Shanghai");
|
||||
private static final DateTimeFormatter TIME_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss XXX");
|
||||
|
||||
private final RuntimeInfo host;
|
||||
|
||||
public DemoController(@Autowired(required = false) RuntimeInfo host) {
|
||||
this.host = host == null ? new RuntimeInfo("", "unknown") : host;
|
||||
}
|
||||
|
||||
@Value("${app.name:spring demo}")
|
||||
private String appName;
|
||||
|
||||
@@ -50,9 +43,9 @@ public class DemoController {
|
||||
body.put("javaHome", System.getProperty("java.home"));
|
||||
body.put("vm", System.getProperty("java.vm.name") + " " + System.getProperty("java.vm.version"));
|
||||
body.put("spring", SpringVersion.getVersion());
|
||||
body.put("application", host.appVersion());
|
||||
body.put("application", "Spring Boot " + SpringBootVersion.getVersion());
|
||||
body.put("os", System.getProperty("os.name") + " " + System.getProperty("os.arch"));
|
||||
body.put("hostname", host.hostname());
|
||||
body.put("hostname", hostname());
|
||||
body.put("port", port);
|
||||
body.put("zoneId", ZoneId.systemDefault().getId());
|
||||
body.put("time", ZonedDateTime.now(TZ8).format(TIME_FMT));
|
||||
@@ -70,19 +63,11 @@ public class DemoController {
|
||||
return body;
|
||||
}
|
||||
|
||||
/** 应用名与版本号;由各示例的实现类提供 */
|
||||
public interface RuntimeInfo {
|
||||
/** 形如 "Spring Boot 3.4.1" 或 "Spring MVC 6.2.1 + Tomcat 10.1.34" */
|
||||
String appVersion();
|
||||
|
||||
String hostname();
|
||||
|
||||
static String hostnameOrUnknown() {
|
||||
try {
|
||||
return InetAddress.getLocalHost().getHostName();
|
||||
} catch (Exception e) {
|
||||
return "unknown";
|
||||
}
|
||||
private static String hostname() {
|
||||
try {
|
||||
return InetAddress.getLocalHost().getHostName();
|
||||
} catch (Exception e) {
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user