我已成功將 Springboot 服務器部署到AWS Elastic Beanstalk,并且可以通過瀏覽器的 URL 訪問它。
我希望能夠從郵遞員向它發送請求。我想我可以使用此代碼列印我將從 Postman 發送請求的 URL:
@Override
public void run(ApplicationArguments args) throws Exception {
try {
String s1 = InetAddress.getLoopbackAddress().getHostAddress();
String hostedAt = s1 ":" environment.getProperty("local.server.port");
logger.info("**The server is hosted at: {}", hostedAt);
} catch (Exception e) {
e.printStackTrace();
}
}
但是,**The server is hosted at 127.0.0.1:8080即使部署到 AWS 也會列印。很明顯,本地主機不是我應該發送請求的地方,那么在哪里呢?
使用我的瀏覽器,如果我導航到應用程式的 URL,那么我就可以Whitelabel error page證明它有效。這是網址:http://spara.us-east-1.elasticbeanstalk.com/
我對此很陌生,所以它可能有些愚蠢,但任何指導都會有所幫助。謝謝!
uj5u.com熱心網友回復:
您現在擁有的是應用程式的公開 URL,即:
http://spara.us-east-1.elasticbeanstalk.com/
您似乎尚未為您的應用設定基本 URL/背景關系路徑。默認背景關系路徑(如果未設定)為空。這意味著,您應該可以使用 Postman 訪問上面的 URL。
但是,如果您確實需要在 application.properties 中為 Spring Boot 應用程式設定基本 URL,則可以將其添加到上面的 URL 并通過郵遞員點擊。
對于 Spring Boot 2.x:
server.servlet.context-path=/your-base-url
Spring Boot 1.2 (<2.0):
spring.data.rest.basePath=/your-base-url
uj5u.com熱心網友回復:
ServletUriComponentsBuilder。fromRequestUri(HttpServletRequest
如果您談論的是 spring boot base URL,應該可以使用
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/349031.html
