package com.swmonk.communityresidents;
import cn.hutool.core.net.url.UrlBuilder;
import cn.hutool.core.net.url.UrlPath;
import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j2;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import java.net.InetAddress;
import java.util.Objects;
@Log4j2
@SpringBootApplication
@MapperScan("com.swmonk.communityresidents.mapper")
public class CommunityResidentsApplication {
@SneakyThrows
public static void main(String[] args) {
SpringApplication app = new SpringApplication(CommunityResidentsApplication.class);
ConfigurableApplicationContext context = app.run(args);
Environment env = context.getEnvironment();
String serverPort = env.getProperty("server.port");
String internalBaseUrl = new UrlBuilder()
.setScheme("http")
.setHost("localhost")
.setPort(Integer.parseInt(Objects.requireNonNull(serverPort)))
.setPath(UrlPath.of(env.getProperty("server.servlet.context-path"), null)).build();
String externalBaseUrl = new UrlBuilder()
.setScheme("http")
.setHost(InetAddress.getLocalHost().getHostAddress())
.setPort(Integer.parseInt(Objects.requireNonNull(serverPort)))
.setPath(UrlPath.of(env.getProperty("server.servlet.context-path"), null)).build();
log.info("\n--------------------------------------------------\n\t" +
"Application '{}' is running! Access URLs:\n\t" +
"Local:\t\t{}\n\t" +
"External:\t{}\n\t" +
"Doc:\t{}/doc.html\n" +
"------------------------------------------------",
env.getProperty("spring.application.name"),
internalBaseUrl,
externalBaseUrl,
externalBaseUrl
);
}
}
springboot终端输出服务访问地址
最新推荐文章于 2024-07-15 18:50:55 发布