在Spring boot 项目启动后,输出访问地址和swagger地址,便于查看和对接。文章来源:https://www.toymoban.com/news/detail-816811.html
import lombok.extern.slf4j.Slf4j;
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.net.UnknownHostException;
@SpringBootApplication
@MapperScan(basePackages = {"com.study.**.repository", "com.study.**.dao", "com.study.**.mapper"})
@Slf4j
public class StaffMailboxApplication {
public static void main(String[] args) throws UnknownHostException {
ConfigurableApplicationContext application = SpringApplication.run(StaffMailboxApplication.class, args);
Environment env = application.getEnvironment();
log.info("\n----------------------------------------------------------\n\t" +
"Application '{}' is running! Access URLs:\n\t" +
"Local: \t\thttp://localhost:{}\n\t" +
"External: \thttp://{}:{}\n\t" +
"Doc: \thttp://{}:{}{}/doc.html\n" +
"\t---Staff Mailbox started successfully\n" +
"\t---启动成功---\n" +
"----------------------------------------------------------",
env.getProperty("spring.application.name"),
env.getProperty("server.port"),
InetAddress.getLocalHost().getHostAddress(),
env.getProperty("server.port"),
InetAddress.getLocalHost().getHostAddress(),
env.getProperty("server.port"),
env.getProperty("server.servlet.context-path"));
}
}
通过Environment去读取配置的名称,端口和路径。 启动后,就可以看到输出的内容,可以直接访问swagger就比较方便。文章来源地址https://www.toymoban.com/news/detail-816811.html
到了这里,关于Spring boot 启动添加访问地址和swagger地址输出的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!