import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;
import java.net.InetAddress;
import java.net.UnknownHostException;
@Slf4j
@Configuration
public class ScreenStartLog implements ApplicationRunner {
@Value("${swagger.groupName}")
private String groupName;
@Value("${spring.profiles.active}")
private String active;
@Value("${server.port}")
private String port;
@Value("${server.servlet.context-path}")
private String path;
public void screenStartLogMsg() throws UnknownHostException {
String ip = InetAddress.getLocalHost().getHostAddress();
log.info("\n-------------------------------------------------------------------\n\t" +
groupName + " 启动成功 当前配置环境:" + active + "\n\t" +
"Local:\t\thttp://localhost:" + port + path + "/\n\t" +
"External:\thttp://" + ip + ":" + port + path + "/\n\t" +
"Doc: \t\thttp://" + ip + ":" + port + path + "/doc.html\n" +
"--------------------------------------------------------------------");
}
@Override
public void run(ApplicationArguments args) throws Exception {
screenStartLogMsg();
}
}
swagger.groupName 是自己在启动配置的yml添加的项目名称