SpringBoot启动类
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
import java.net.InetAddress;
import java.net.UnknownHostException;
@SpringBootApplication
@Slf4j
public class App {
public static void main(String[] args) throws UnknownHostException {
ConfigurableApplicationContext application= SpringApplication.run(App.class, args);
Environment env = application.getEnvironment();
String ip = InetAddress.getLocalHost().getHostAddress();
String port = env.getProperty("server.port");
String path = env.getProperty("server.servlet.context-path");
if (StringUtils.isEmpty(path)) {
path = "";
}
log.info("\n----------------------------------------------------------\n\t" +
"本地访问地址: \t\thttp://localhost:" + port + path + "\n\t" +
"IP访问访问地址: \thttp://" + ip + ":" + port + path + "\n\t" +
"----------------------------------------------------------");
}
}
本文介绍了如何使用Spring Boot创建一个简单的应用程序,包括SpringApplication的运行,环境变量获取,以及本地和IP访问地址的打印。
936

被折叠的 条评论
为什么被折叠?



