我是靠谱客的博主 欣慰砖头,这篇文章主要介绍服务器控制端口获取信息,如何在Spring Boot中获取本地服务器主机和端口?,现在分享给大家,希望可以做个参考。

我正在启动一个Spring Boot应用程序mvn spring-boot:run.

我@Controller的一个需要有关应用程序正在侦听的主机和端口的信息,即localhost:8080(或127.x.y.z:8080).在Spring Boot文档之后,我使用了server.address和server.port属性:

@Controller

public class MyController {

@Value("${server.address}")

private String serverAddress;

@Value("${server.port}")

private String serverPort;

//...

}

在启动应用程序时mvn spring-boot:run,我得到以下异常:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myController': Injection of autowired dependencies failed; nested exception is

org.springframework.beans.factory.BeanCreationException: Could not autowire field: ... String ... serverAddress; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'server.address' in string value "${server.address}"

双方server.address并server.port不能自动装配.

如何找到Spring Boot应用程序绑定的(本地)主机/地址/ NIC和端口?

最后

以上就是欣慰砖头最近收集整理的关于服务器控制端口获取信息,如何在Spring Boot中获取本地服务器主机和端口?的全部内容,更多相关服务器控制端口获取信息,如何在Spring内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(131)

评论列表共有 0 条评论

立即
投稿
返回
顶部