gpt4 book ai didi

spring - 如何使用 Spring Boot 从 tomcat 服务器部署 html

转载 作者:行者123 更新时间:2023-11-28 23:20:18 25 4
gpt4 key购买 nike

所以,答案可能非常简单,但我似乎无法弄清楚。

我已经根据本教程设置了一个 REST 网络服务:https://spring.io/guides/gs/rest-service/并使用 postman 设置了 Requestmapping 和所有内容,最终工作如我所愿。

我正在本地设置我的站点,但是当我尝试使用 jquery 发送 get 请求时,我收到以下错误:Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

所以我明白问题是我正在尝试从 file://运行我的 html 并且解决方案是从 tomcat 服务器上的本地主机运行它并在另一个主题中找到这个答案:Deploying just HTML, CSS webpage to Tomcat

但是,我找不到这样的 webapps 文件夹,我假设这是因为我的 tomcat 服务器是使用 maven 和 springboot 部署的。那么我的html/js怎么部署到tomcat服务器上呢?

我正在使用 Mac 和 IntelliJ 工作。

最佳答案

在您的 spring boot 应用程序中,您可以将 index.html 文件放在 src/main/resources/static 目录中,应用程序将提供该文件。

您也可以尝试在 spring boot 中配置 CORS,参见 this answer链接。

关于spring - 如何使用 Spring Boot 从 tomcat 服务器部署 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44736295/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com