com.gccloud.starter.common.init.JdkCheckCommandLineRunner Maven / Gradle / Ivy
package com.gccloud.starter.common.init;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
/**
* jdk 类型检查
*
* @author liuchengbiao
* @date 2023-03-17 10:52
*/
@Slf4j
@Order(1)
@Component
@ConditionalOnProperty(prefix = "gc.starter.component", name = "JdkCheckCommandLineRunner", havingValue = "JdkCheckCommandLineRunner", matchIfMissing = true)
public class JdkCheckCommandLineRunner implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
try {
String javaHome = System.getenv("JAVA_HOME");
if (StringUtils.isNotBlank(javaHome) && javaHome.toLowerCase().contains("openjdk")) {
// 不建议使用open JDK
log.error("不建议使用 OpenJDK,如果一定要使用请确保 jstack、jps 命令能够执行");
log.error("不建议使用 OpenJDK,如果一定要使用请确保 jstack、jps 命令能够执行");
log.error("不建议使用 OpenJDK,如果一定要使用请确保 jstack、jps 命令能够执行");
}
} catch (Exception e) {
log.error(ExceptionUtils.getStackTrace(e));
}
}
}