如何为我的 Spring Boot webapp 选择 URL? [英] How do I choose the URL for my Spring Boot webapp?

查看:28
本文介绍了如何为我的 Spring Boot webapp 选择 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Spring Boot 创建一个 Web 应用程序,但我不确定如何将 URL 从 localhost:8080 更改为类似 localhost:8080/myWebApp 的内容.

I am using Spring Boot to create a web app, and I am not sure how to change the URL from localhost:8080 to something like localhost:8080/myWebApp.

我在网上看到很多资源都引用了 application.properties 文件并将其添加到类路径中.但是,我不确定把它放在哪里.

I have a seen a lot of resources online referencing an application.properties file and adding that to the classpath. But, I'm not sure exactly where to put that.

  • 在我的 src/main/resources 中?

我将如何分配文件中的 URL?

How would I assign the URL within the file?

推荐答案

您需要将属性 server.contextPath 设置为 /myWebApp.

You need to set the property server.contextPath to /myWebApp.

查看这个 部分文档

设置该属性的最简单方法是在您使用的属性文件中(最有可能是 application.properties),但 Spring Boot 提供了很多不同的设置属性的方法.查看 文档的这一部分

The easiest way to set that property would be in the properties file you are using (most likely application.properties) but Spring Boot provides a whole lot of different way to set properties. Check out this part of the documentation

编辑

正如@AbdullahKhan 所提到的,从 Spring Boot 2.x 开始,该属性已被弃用,应替换为 server.servlet.contextPath,正如 这个答案.

As has been mentioned by @AbdullahKhan, as of Spring Boot 2.x the property has been deprecated and should be replaced with server.servlet.contextPath as has been correctly mentioned in this answer.

这篇关于如何为我的 Spring Boot webapp 选择 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆